Forum Discussion
Dax Measure
- 1 year ago
Hi LoganFFS ,
Thank you for reaching out to us on the Microsoft Fabric Community Forum.
Please follow below steps.
Step 1: Add an Index Column, Since there’s no timestamp, we need an index column that gives us the row order. Do this in
Power Query:Sort by Date, Name, Symbol. Add an Index column starting from 1 (call it RowIndex).
Step 2:DAX Measure to Get First Buy After Each Sell
Create a measure with below DAX
AverageFirstBuyAfterSell =
VAR SellTable =
FILTER (
ALL ( Table ),
Table[Action] = "Sell"
)
VAR FirstBuyAfterSellTable =
ADDCOLUMNS (
SellTable,
"FirstBuyPrice",
CALCULATE (
MINX (
TOPN (
1,
FILTER (
ALL ( Table ),
Table[RowIndex] > EARLIER ( Table[RowIndex] )
&& Table[Action] = "Buy"
),
Table[RowIndex], ASC
),
Table[Price]
)
)
)
RETURN
AVERAGEX (
FirstBuyAfterSellTable,
[FirstBuyPrice]
)Step 3 : Drag all the fields in table visual.
Please refer sample data and output snaps and PBIX file.
If my response has resolved your query, please mark it as the "Accepted Solution" to assist others. Additionally, a "Kudos" would be appreciated if you found my response helpful.
Thank you
Hi LoganFFS ,
Thank you for reaching out to us on the Microsoft Fabric Community Forum.
Please follow below steps.
Step 1: Add an Index Column, Since there’s no timestamp, we need an index column that gives us the row order. Do this in
Power Query:
Sort by Date, Name, Symbol. Add an Index column starting from 1 (call it RowIndex).
Step 2:DAX Measure to Get First Buy After Each Sell
Create a measure with below DAX
AverageFirstBuyAfterSell =
VAR SellTable =
FILTER (
ALL ( Table ),
Table[Action] = "Sell"
)
VAR FirstBuyAfterSellTable =
ADDCOLUMNS (
SellTable,
"FirstBuyPrice",
CALCULATE (
MINX (
TOPN (
1,
FILTER (
ALL ( Table ),
Table[RowIndex] > EARLIER ( Table[RowIndex] )
&& Table[Action] = "Buy"
),
Table[RowIndex], ASC
),
Table[Price]
)
)
)
RETURN
AVERAGEX (
FirstBuyAfterSellTable,
[FirstBuyPrice]
)
Step 3 : Drag all the fields in table visual.
Please refer sample data and output snaps and PBIX file.
If my response has resolved your query, please mark it as the "Accepted Solution" to assist others. Additionally, a "Kudos" would be appreciated if you found my response helpful.
Thank you
Hi LoganFFS ,
We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet.do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.
Thank you.
- v-dineshya1 year ago
Community Support
Hi @LoganFFS ,
We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet.do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.
Thank you.
- v-dineshya1 year ago
Community Support
Hi @LoganFFS ,
We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet.do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.
Thank you.