This is a copy of another excel sheet I'm working on, this is the query I've:
=query(indirect("'"&VLOOKUP(C6,BANK_CARDS!$B$2:$F$4,5, false)&"'!$B$3:K"), "select sum(J) where F='"&$H6&"' and G='"&I6&"' and H="&C6&" and month(C) 1="&month(today())&" label sum(J)''",0)
This part, gets the cell value to get the name of the credit card which we'll be getting the data transactions:
indirect("'"&VLOOKUP(C6,BANK_CARDS!$B$2:$F$4,5, false)&"'!$B$3:K")
This should return the sum of the quantity in J based on the other conditions (on the same month, same credit card number, category and subcategory).
"select sum(J) where F='"&$H6&"' and G='"&I6&"' and H="&C6&" and month(C) 1="&month(today())&" label sum(J)''"
I don't know how to fix or improve this, here is the link of the google-sheet.