How to multiply B1 with C1, B2 with C2, Bn with Cn and Sum them? - excel

This is my sheet:
Goods Type Quantity / Geram Gold Price 750K Price of Exchange
Gold 100 1,554.00 0
Silver 500 235.00 0
Euro 200 0.00 1.01
Pond 50 0.00 0.97
Gold 100 1,554.00 0
Silver 500 235.00 0
Euro 200 0.00 1.00
Pond 50 0.00 0.99
I want to do to this:
If Goods Type is Gold: multiply Quantity / Geram by Gold Price.
In my case it should be: (100 * 1554) + (100 * 1554) = 310800, and if I add more entries in the future, it should add more.
I have this cell in my current sheet: If Goods Type is Gold, then sumif all Quantity / Geram in another cell which is now 200.

Use SUMPRODUCT: sumproduct
=SUMPRODUCT((A2:A9="Gold")*B2:B9*C2:C9)
It multiplies TRUE/FALSE (result of A2:A9="Gold") with quantity and price and sums everything (in this case = 155400 + 0 + 0 + 0 + 15540 + 0 + 0 + 0))
Result:
Adjust ranges to your data.

You can make a SumProduct() for three columns, so you can create an IF() formula for getting 1 in case of "Gold" and 0 else. This leads to following kind of formula:
=SUMPRODUCT(IF(A2:A6="Gold",1,0),B2:B6,C2:C6)
See following screenshot:

Related

How to calculate average price of open position of stocks Excel Table

I have a simple table with some dummy data to simulate stock trades. I know the its model is not exactly right, but it does comply with the basics and that's what I'm looking for.
The answer I'm looking for is how would I calculate the data on column 12. It's supposed to show the Average Price of the position at that date. If the position opened with the current row then the average price is the actual price of the trade, however the position can be increased or decreased with new prices and I want to know the average price up to that date (last two rows have this example).
Column 13 (What I got so far) has this definition*: =SUMPRODUCT([Delta Position];--([Date Trade]<=[#[Date Trade]]);--([Position After Trade]=[#[Position After Trade]]))
*actually the there's two more columns, Trader and Maturity Date, these two are used to filter data and are not shown to make it more readable: --([Person]=[#Person]);--([Month]=[#month])
(second row just shows the definition of the simpler columns)
Date Trade
Price
op
Qty
Total
Accumulated Before
Accumulated After
Position After Trade
Qty Delta Position
Delta Position
Value of Open Position
What I got so far
Average Price Open Position
C1
C2
C3
C4
C5 = C2 x C4
C6
C7
C8
C9
C10 = C9 * C2
C11
C12
C13 = C11 / C7
2021-12-06
328
Buy
99
32472
0
99
long
99
32472
HELP: 32472
32472
328
2021-12-13
291
Sell
99
28809
99
0
zero
0
0
HELP: 0
0
0
2022-01-31
190
Sell
120
22800
0
-120
short
-120
-22800
HELP: -22800
-22800
190
2022-02-14
165
Buy
120
19800
-120
0
zero
0
0
HELP: 0
0
0
2022-04-20
113,7
Sell
200
22740
0
-200
short
-200
-22740
HELP: -22740
-45540
113,7
2022-06-21
74,333
Buy
300
22299,9
-200
100
long
100
7433,3
HELP: 7433.3
39905,3
74,333
2022-08-16
86
Buy
50
4300
100
150
long
50
4300
HELP: 11733.3
44205,3
78,222
The average price of an open position is calculated by this fórmula
Average price fórmula
Iteratively you can obtain this fórmula:
Iterative fórmula
First row (first operation) => Average price = M3 = If(C3='Buy';B3;-B3)
Second row => Average price => Average price = M4 = ((M3F4)+(If(C4='Buy';B4C4;-B4*C4) )) / G4
Next rows you only have to iterate fórmula.
I hope this can help you.

Create unique list from 2 columns and sum values per row based on that unique list from 2 value columns

Having scoured numerous posts I am still struggling to find a solution for a report I am trying to transition over to PowerBI, from MS Excel.
Problem
Create a table in the report section of PowerBI, which has a unique list of currencies (based on 2 columns) and their corresponding FXexposure, which are defined based on each currency leg from 2 columns. Below I have shown the source data and workings I use in Excel, which i am trying to replicate.
Source data (from database table)
a
b
d
d
e
f
g
Instrument
Currency 1
Currency 2
FX nominal 1
FX nominal 2
FXNom1 - Gross
FXNom2 - Gross
FWD EUR/USD
EUR
USD
-7.965264529
7.90296523
7.97
7.90
FWD USD/JPY
USD
JPY
1.030513307
-1.070305687
1.03
1.07
Instrument 1
USD
1.75862819
1.76
0.00
Instrument 2
USD
TRY
0
3.45E-04
0.00
0.00
Instrument 3
JPY
1.121782037
1.12
0.00
Instrument 4
EUR
6.2505079
6.25
0.00
FWD EUR/CNH
EUR
CNH
0.007591392
3.00E-09
0.01
0.00
Instrument 5
RUB
6.209882675
6.21
0.00
F2 = ABS(FX nominal 1)
G2 = ABS(FX nominal 2)
Report output in excel
a
b
c
d
e
FX
Long
Short
Net
**Gross **
0
0.00
0.00
0.00
0.00
RUB
6.21
0.00
6.21
6.21
EUR
6.26
-7.97
-1.71
14.22
JPY
1.12
-1.07
0.05
2.19
USD
10.69
0.00
10.69
10.69
CNH
0.00
0.00
0.00
0.00
TRY
0.00
0.00
0.00
0.00
My Excel formulas are below to recreate what i am looking for.
A2: =IFERROR(LOOKUP(2, 1/(COUNTIF(Report!$A$1:A1,Data!$B$2:$B$553)=0), Data!$B$2:$B$553), LOOKUP(2, 1/(COUNTIF(Report!$A$1:A1, Data!$C$2:$C$553)=0), Data!$C$2:$C$553))
B2: =((SUMIFS(Data!$D$2:$D$553, Data!$B$2:$B$553, Report!$A2, Data!$D$2:$D$553, ">0"))+(SUMIFS(Data!$E$2:$E$553, Data!$C$2:$C$553, Report!$A2, Data!$E$2:$E$553, ">0")))
C2: =((SUMIFS(Data!$D$2:$D$553, Data!$B$2:$B$553, Report!$A3, Data!$D$2:$D$553, "<0"))+(SUMIFS(Data!$E$2:$E$553, Data!$C$2:$C$553, Report!$A3, Data!$E$2:$E$553, "<0")))
D2: =(SUMIF(Data!$B$1:$B$553,Report!$A3,Data!$D$1:$D$553)+SUMIF(Data!$C$1:$C$553,Report!$A3,Data!$E$1:$E$553))
E2: =(SUMIF(Data!$B$1:$B$554,Report!$A3,Data!$F$1:$F$554)+SUMIF(Data!$C$1:$C$554,Report!$A3,Data!$G$1:$G$554))
Now I believe I've managed to find a hack by using the UNIQUE/SELECTCOLUMNS function, but when you try and graph the output it is very small (as if there is other data it is trying to find behind the scenes). Note i tend to filter on date to get the output I need (this is mapped using relationships across other data tables).
FX =
DISTINCT (
UNION (
SELECTCOLUMNS ( DATA, "Date", [DATE], "Currency", [CURRENCY1], "FXNom", [FXNOMINAL1] ),
SELECTCOLUMNS ( DATA, "Date", [DATE], "Currency", [CURRENCY2], ,"FXNom", [FXNOMINAL2] )
)
)
If anyone has any ideas I would be very grateful as I still feel my workaround is more of a lucky hack.
Thanks!
The approach that you're using looks nearly ideal. From a dimensional model perspective, you want one column for values and one column for currency labels. So selecting those pairs as different tables and appending with UNION is the right way to go. Generally, I think it's better to do all the transformation you can in power query, using DAX this way can lead to some limitations.
But if we're going with DAX, I do think you want to get rid of DISTINCT. This could cause identical positions to be collapsed into a single row and you'd lose data this way.
FX =
UNION (
SELECTCOLUMNS ( FX_Raw, "Date", "FakeDate", "Currency", [CURRENCY 1], "FXNom", [FX nominal 1] ),
SELECTCOLUMNS ( FX_Raw, "Date", "FakeDate", "Currency", [CURRENCY 2], "FXNom", [FX nominal 2] )
)
And then a few measures:
Long =
CALCULATE(sum(FX[FXNom]), FX[FXNom] >= 0)
Short =
CALCULATE(sum(FX[FXNom]), FX[FXNom] < 0)
Gross =
SUMX( FX, if(FX[FXNom] > 0, FX[FXNom], 0-FX[FXNom]))
Net =
SUM(FX[FXNom])
Seems to produce the desired result:

How to do SUMPRODUCT with percentage and blank cells

I am trying to do SUMPRODUCT in Google Sheets but in a more complicated situation.
I want to sum product with percentage instead of decimal number.
This is what I am doing now, and it works just fine:
A B C D
Price Tax Cashback
100 1.09 0.95
80 1 1
50 1.09 0.95
Total =SUMPRODUCT(B:B, C:C, D:D)
What I actually want to do is
A B C D
Price Tax Cashback
100 9% 5%
80
50 9% 5%
Total ???
Use
=SUMPRODUCT(B2:B, 1+C2:C, 1-D2:D)

Excel need to sum distinct id's value

I am struggling to find the sum of distinct id's value. Example given below.
Week TID Ano Points
1 111 ANo1 1
1 112 ANo1 1
2 221 ANo2 0.25
2 222 ANo2 0.25
2 223 ANo2 0.25
2 331 ANo3 1
2 332 ANo3 1
2 333 ANo3 1
2 999 Ano9 0.25
2 998 Ano9 0.25
3 421 ANo4 0.25
3 422 ANo4 0.25
3 423 ANo4 0.25
3 531 ANo5 0.5
3 532 ANo5 0.5
3 533 ANo5 0.5
From the above data i need to bring the below result. Could anyone help please using some excel formula?
Week Points_Sum
1 1
2 1.50
3 0.75
You say "sum of distinct id's value"? All the IDs are different so I'm assuming you want to sum for each different "Ano" within the week?
=SUM(IF(FREQUENCY(IF(A$2:A$17=F2,MATCH(C$2:C$17,C$2:C$17,0)),ROW(A$2:A$17)-ROW(A$2)+1),D$2:D$17))
confirmed with CTRL+SHIFT+ENTER
where F2 contains a specific week number
Assumes that each "Ano" will always have the same points value
Probably not the most efficient solution... but this array formula works:
= SUMPRODUCT(IF($A$2:$A$15=$F2,$D$2:$D$15),1/MMULT((IF($A$2:$A$15=$F2,$D$2:$D$15)=
TRANSPOSE(IF($A$2:$A$15=$F2,$D$2:$D$15)))+0,(ROW($A$2:$A$15)>0)+0))
Note this is an array formula, so you have to press Ctrl+Shift+Enter after typing this formula instead of just Enter.
See working example below. This formula is in cell G2 and dragged down.

How to exclude 0 from MIN formula unless that is the only option?

I want excel to select the lowest number excluding 0 from the D and G Columns and display it in the H Column. Right now my table looks like this:
A B C D E F G H
1 1 150.00 52 7800.00 0 569.99 0.00 =SMALL((G5,J5),INDEX(FREQUENCY((D1,G1),0),1)+1)
2 0 50.00 52 0.00 0 750.00 0.00 =SMALL((G5,J5),INDEX(FREQUENCY((D2,G2),0),1)+1)
Row 1 works as expected and selects 7800.00 and ignores the 0, but for row 2 selects neither because they're both 0 and displays #NUM!. Any chance that I can fix this?
As Mr SeanC said it was as easy as just using =IFERROR:
=IFERROR(SMALL((G5,J5),INDEX(FREQUENCY((D2,G2),0),1)+1),0)

Resources