Sum product of two table by column matching - excel

I have two tables, first with currency and value and the second one with currency and x-rate.
by matching currency columns from two tables, I want to multiply and sum the values.
Currency
value
EUR
10
GBP
20
CHF
30
EUR
40
GBP
50
And the second one
Currency
x_rate
EUR
1
GBP
1.2
CHF
1.3
The result should be: 10*1 + 40*1 + 20*1.2 + 50*1.2 + 30*1.3 = 173

Use array formula:
=SUMPRODUCT(B2:B6*TRANSPOSE(E2:E4)*(A2:A6=TRANSPOSE(D2:D4)))
Array formula after editing is confirmed by pressing ctrl + shift + enter

=SUMPRODUCT(($B$2:$B$6)*INDEX($E$2:$E$4,MATCH($A$2:$A$6,$D$2:$D$4,0)))
Where $A$2:$B$6 is the first table and $D$2:$E$4 is the second table.

Related

Excel Array formula, use info from one IF result as criteria in another IF?

Context
I'm building a financial dashboard, but I'm having troubles to get a formula that fit my client's need.
I'm consolidating amount in different currencies, but for a special indicator,
I need to build a YTD with the Exchange Rate of the last month.
Something like :
(Amount_$_Jan + Amount_$_Feb)*ExRate_$_Feb + (Amount_£_Jan + Amount_£_Feb)*ExRate_£_Feb
OR
(Amount_$_Jan + Amount_$_Feb + Amount_$_Mar)*ExRate_$_Mar + (Amount_£_Jan + Amount_£_Feb + Amount_£_Mar)*ExRate_£_Mar
My issue
In the data, I have multiple currencies and they'll be more to come, so I cannot list the currencies.
I'm trying to :
get the value of the currency of each line that matches the criteria of the first IF
to use it in my second IF to find the exchange range for that currency
for the month I'm calculating for,
with: Named_Rg[Currency]=Named_Rg[Currency]
which is obviously always true, but it is the only syntax I've tried that I could validate...
I've tried :
Named_Rg[Currency]=[#[Currency]]
Named_Rg[Currency]=[Currency]
But both are giving errors (I'm using that formula outside of the table Named_Rg)
I know I can write a function in VBA, but I'd prefer to keep an xlsx.
My formula
I've removed some tests, like testing the year, which are not pertinent for the question.
I'm using it on a another sheet that the one where the table Named_Rg is :
{=SUM(IF(Named_Rg[Month]<=MONTH(X$5);Named_Rg[Amount]*IF(AND(Named_Rg[Month]=MONTH(X$5);Named_Rg[Currency]=Named_Rg[Currency]);Named_Rg[Chg to €];0);0))}
How can I refer to the Row/Currency found with the first IF in the second one?
Sample Data
That is just a sample, I'll have multiples rows per month and currency.
Year Month Currency Chg to € Amount
2017 1 EUR 1 20
2017 1 USD 0.6 30
2017 1 LST 2 40
2017 2 EUR 1 200
2017 2 USD 0.7 300
2017 2 LST 2.2 400
2017 3 EUR 1 2000
2017 3 USD 0.8 3000
2017 3 LST 2.4 4000
CSV format :
Year;Month;Currency;Chg to €;Amount
2017;1;EUR;1;20
2017;1;USD;0.6;30
2017;1;LST;2;40
2017;2;EUR;1;200
2017;2;USD;0.7;300
2017;2;LST;2.2;400
2017;3;EUR;1;2000
2017;3;USD;0.8;3000
2017;3;LST;2.4;4000
Expected results :
YTD last chg (Jan) : 118 = 20*1+30*0.6+40*2
YTD last chg (Feb) : 1419 = (20+200)*1+(30+300)*0.7+(40+400)*2.2
YTD last chg (Mar) : 15540 = (20+200+2000)*1+(30+300+3000)*0.8+(40+400+4000)*2.4
Array formula do not like the AND() or OR() operators. They need to be substituted with * or + respectively.
So your:
AND(Named_Rg[Month]=MONTH(X$5);Named_Rg[Currency]=Named_Rg[Currency])
Should be:
(Named_Rg[Month]=MONTH(X$5))*(Named_Rg[Currency]=Named_Rg[#Currency])
So the formula would be:
=SUM(IF(Named_Rg[Month]<=MONTH(X$5);Named_Rg[Amount]*IF((Named_Rg[Month]=MONTH(X$5))*(Named_Rg[Currency]=Named_Rg[#Currency]);Named_Rg[Chg to €])))
Remember that this is an array formula and needs to be confirmed with Ctrl-Shift-Enter
But I think you want this formula instead to get the desired output:
=SUMPRODUCT(SUMIFS(Named_Rg[Amount],Named_Rg[Month],"<=" & MONTH(X5),Named_Rg[Currency],Named_Rg[Currency])*(Named_Rg[Month]=MONTH(X5))*(Named_Rg[Chg to €]))
Change the , to your ; for your local settings.

Finding Date difference based on the given value

I have a data which looks like below.
ID Date Currency
1 9/29/2015 INR
1 10/28/2015 INR
1 10/29/2015 INR
1 11/8/2015 EUR
1 11/11/2015 EUR
1 11/23/2015 EUR
1 11/24/2015 EUR
1 11/25/2015 INR
1 11/27/2015 EUR
1 12/1/2015 EUR
1 12/2/2015 CEZ
1 12/3/2015 CEZ
1 12/15/2015 CEZ
1 12/18/2015 INR
1 12/29/2015 INR
I want to calculate the difference between the date when the given the currency is same. For example, the first three are of same currency and therefor the difference will be calculated for the date 1 and date 3. Similarly, for rest of the rows I need to calculate. Precisely, the output looks like below.
ID Date Date2 Currency Difference
1 9/29/2015 10/29/2015 INR 30
1 11/8/2015 11/24/2015 EUR 16
1 11/25/2015 11/25/2015 INR 0
1 11/27/2015 12/1/2015 EUR 4
1 12/2/2015 12/15/2015 CEZ 13
1 12/18/2015 12/29/2015 INR 11
I really appreciate if someone helps me to achieve this using excel
Assuming the three columns are placed in column A, B and C and you start in row 1, then you can append two additional columns.
Cell D2, pull formula down:
=IF(C2=C1,D1,B2)
Cell E2, pull formula down:
=IF(C2=C3,"",B2-D2)
Column E now contains the desired result. For convenience, you can place a filter on the table to filter out the empty values in that column.

Nested array formulas

I want a summation of rates. Let me explain it: I would like to sum the numbers in column D that matches 2 conditions (green rows in excel). First one: column F equal to "closed". Second one: column C equal to those numbers which in turn matches the following condition: column F equal to "Partial Sold". At the same time, EACH number in the previous summation might be divided by the number of column D which matches "Partial Sold" in column F.
There is the example with the table/figure I attached: (4510 / 9820) + (6500 / 9820) + (9100 / 15400) + (2388 / 2995) + (12400 / 9820) + (2904 / 5855).
My cells would be: (D69 / D66) + (D70 / D66) + (D76 / D74) + (D82 / D78) + (D83 / D66) + (D84 / D72).
#Jeeped with your cells would be: (D6 / D3) + (D7 / D3) + (D13 / D11) + (D19 / D15) + (D20 / D3) + (D21 / D9)
.. C D E F
65 # Total Side Condition
66 1 9820 Buy Partial Sold
67 2 3850 Buy Closed
68 3 7151 Buy Partial Sold
69 1 4510 Sell Closed
70 1 6500 Sell Closed
71 4 8180 Buy Open
72 5 5855 Buy Partial Sold
73 6 2553 Buy Open
74 7 15400 Buy Partial Sold
75 2 4600 Sell Closed
76 7 9100 Sell Closed
77 8 7531 Buy Open
78 9 2995 Buy Partial Sold
79 3 3000 Sell Closed
80 10 8691 Buy Open
81 3 2500 Sell Closed
82 9 2388 Sell Closed
83 1 12400 Sell Closed
84 5 2904 Sell Closed
85 11 3848 Buy Open
86 12 7745 Buy Open
To do it in one step with an array formula you could use:
=SUM(IFERROR((D66:D86*(F66:F86="Closed"))/((C66:C86=TRANSPOSE(C66:C86))*TRANSPOSE(D66:D86*(F66:F86="Partial Sold"))),0))
This is an array formula and must be confirmed with Ctrl+Shift+Enter↵.
it will generate a 2D-array holding the original values for closed as rows and divides this 1D array by this:
buils up 2D-array by col C = transposed col C
multiply each row by col D
set all items in each row to 0 if not "Partial Sold"
for each div by 0 the IFERROR will set it to 0
and this all in the SUM will give you your output
I too would recommend using a helper column. You don't need to use array formulas to get to the answer though. You can use the following in the next available column:
=IF(F66="Closed",IFERROR(D66/SUMIFS($D$66:$D$86,$F$66:$F$86,"Partial Sold",$C$66:$C$86,C66),0),0)
This will return values for everything that matches your criteria, and zeroes for everything else. Then you can just take the sum of this helper column as your final summation of rates.
If you really don't want to use a helper column, you can wrap the helper column formula in a SUM and swap out the individual cell references for arrays (i.e. swap F66 for $F$66:$F$86, and so on), then enter it as an array formula with Ctrl+Shift+Enter↵. The whole thing would look like this:
=SUM(IF($F$66:$F$86="Closed",IFERROR($D$66:$D$86/SUMIFS($D$66:$D$86,$F$66:$F$86,"Partial Sold",$C$66:$C$86,$C$66:$C$86),0),0))
I do not see this being done without a helper column. In an unused column to the right of F66, put this array¹ formula.
=IF(AND(OR(C66=INDEX(C$66:C$86*(F$66:F$86="Partial Sold"), , )), F66="Closed"), D66/INDEX(D$66:D$86, AGGREGATE(15, 6, ROW($1:$21)/((C$66:C$86=C66)*(F$66:F$86="Partial Sold")), 1)), "")
Fill down as necessary. The result will be the sum of those 'helper' numbers.
        
Even if this could be done in a single formula, the calculation overhead would likely be prohibitive. Splitting a portion of the array calculations off to a helper column that can directly reference the value in column C for another lookup reduces this significantly.
¹ Array formulas need to be finalized with Ctrl+Shift+Enter↵. Once entered into the first cell correctly, they can be filled or copied down or right just like any other formula. Try and reduce your full-column references to ranges more closely representing the extents of your actual data. Array formulas chew up calculation cycles logarithmically so it is good practise to narrow the referenced ranges to a minimum. See Guidelines and examples of array formulas for more information.

SUMPRODUCT INDEX MATCH

With the following data:
A B
1 CUMULATIVE PERCENTAGE OF ITEMS PRODUCED PER MONTH ("COMPLETION_TABLE")
2 Type Month 1 Month 2
3 KITTENS 0 10
4 FISH 0 20
5 BANANAS 2 5
6 APPLES 0 0
7 PEARS 0 5
8 KITTENS 0 5
9
10
11 PRICES TABLE ("PRICES_TABLE")
12 Type Value
13 APPLES 1000
14 BANANAS 5000
15 PEARS 3000
16 FISH 4000
17 KITTENS 2000
I'm attempting to use the SUMPRODUCT function to calculate the percentage change in each month and use that value as a multiple of the prices table to provide a total price per month across all types that have been produced.
I can calculate the movement as:
=SUMPRODUCT((COMPLETION_TABLE[Month 2]-COMPLETION_TABLE[Month 1]))
... but I then need to calculate the portion of the individual movement values against the price for that type and sum the resulting products together. I have been using various INDEX / MATCH combinations without much luck.
As an example: BANANAS which should =(5-2)*5000.
Written as expanded arrays I would like to do
({10;20;5;0;5;5}-{0;0;2;0;0;0})*{2000;4000;5000;1000;3000;2000}.
Use of SUMPRODUCT implies you want a single figure result. You can use SUMIF as a "pseudo lookup" within SUMPRODUCT to get the prices, e.g.
=SUMPRODUCT(C3:C8-B3:B8,SUMIF(A13:A17,A3:A8,B13:B17))
That would get you a result of 140,000 for your example
From your question I understand the result you want is an array. This is what you get with this formula:
=INDEX($B$13:$B$17,MATCH($A3:$A8,$A$13:$A$17,0))*($C3:$C8-$B3:$B8)
entered as an array formula using Ctrl Shift Enter.
I am sure there is something simpler. I am assuming that the Type in the Price Table are unique:
{=(SUM((A13=$A$3:$A$8)*$C$3:$C$8)-SUM((A13=$A$3:$A$8)*$B$3:$B$8))*SUM((A13=$A$13:$A$17)*$B$13:$B$17)

Excel: calculage sum of matched cells multiplayed by percent in another cell

I have an Excel table with my banks account like this
A B C E
1 Currency Percent Value Banks Account
2 USD 5 100 8923781
3 Eur 7 200 Ea84382
4 USD 6 900 PayY8908
So I need to calculate how much USD I will earn in current month from all deposits (Value) if we know interest rate's (Percent) for each of bank's acoounts.
For first account the formula will be =C2/100*B2/12 and for second =C4/100*B4/12
The problem that I don't understand how to automatically filter only USD accounts (SUMIF???). And I can't figure out how to do this using only one cell.
You could use SUMIF, if you would use a helper Column:
A B C D E
1 Currency Percent Value Banks Account Monthly earned
2 USD 5 100 8923781 0,416666667
3 Eur 7 200 Ea84382 1,166666667
4 USD 6 900 PayY8908 4,5
Formula in E2:
=C2/100*B2/12
fill down.
Now you could have:
=SUMIF($A$2:$A$10,"USD",$E$2:$E$10)
to sum the USD.
Or, without helper Column, you could use the "swiss army knife" SUMPRODUCT:
=SUMPRODUCT(($A$2:$A$10="USD")*($C$2:$C$10/100*$B$2:$B$10/12))
Greetings
Axel

Resources