Assume I have the following data:

I want to do a calculation based on each currency and amount. Something like:

So money in (for USD) will be the sum of column H where the amount is positive, and the currency is USD. Money out (for USD) will be the sum of column H where the amount is negative, and the currency is USD.

How to calculate this? I'm thinking of using SUMIFS, but I always get Err:502. My formula is :

=SUMIFS($H$2:$H$65440, G2, "USD", H2, ">0")