Forum Discussion
Dax Table Summarize using Lookup
Hi,
I want to summarize a table keeping the corresponding values/Dates from a neighbouring column after an expression.
As the example shows I'm hoping to summarize the animals, calculate the earlisest (min) Analysis Date, and keep it's neighbouring FInalise Date.
Appreciate any help.
Thanks
IDEAL_Backtest_Details = ADDCOLUMNS( SUMMARIZE(Backtest_Details, Backtest_Details[Animals], "Analysis Date", min(Backtest_Details[Analysis Date]) ) , "Final Date", LOOKUPVALUE(Backtest_Details[Final Date], Backtest_Details[Animals], [Animals], Backtest_Details[Analysis Date], [Analysis Date]) )something like this?
IP: Backtest_Details
OP:
Hi NMOORE
if you're looking for a calculated table solution, you may try
NewTable =
GENERATE (
VALUES ( 'Table'[Animals] ),
CALCULATETABLE (
TOPN (
1,
SELECTCOLUMNS (
'Table',
"Analysis Date", 'Table'[Analysis Date],
"Finalise Date", 'Table'[Finalise Date]
),
'Table'[Analysis Date], ASC
)
)
)Thanks alot for this, I was playing around with it for a while trying to do exactly this but just couldnt get there. Much appreciated.
7 Replies
- sevenhills
Super User
IDEAL_Backtest_Details = ADDCOLUMNS( SUMMARIZE(Backtest_Details, Backtest_Details[Animals], "Analysis Date", min(Backtest_Details[Analysis Date]) ) , "Final Date", LOOKUPVALUE(Backtest_Details[Final Date], Backtest_Details[Animals], [Animals], Backtest_Details[Analysis Date], [Analysis Date]) )something like this?
IP: Backtest_Details
OP:
- NMOORE
Helper II
Thanks alot for this, I was playing around with it for a while trying to do exactly this but just couldnt get there. Much appreciated.
- sevenhills
Super User
Please mark my reply as solution if you like it and also helps for the folks in future those who refer this thread.
- tamerj1
Community Champion
Hi NMOORE
if you're looking for a calculated table solution, you may try
NewTable =
GENERATE (
VALUES ( 'Table'[Animals] ),
CALCULATETABLE (
TOPN (
1,
SELECTCOLUMNS (
'Table',
"Analysis Date", 'Table'[Analysis Date],
"Finalise Date", 'Table'[Finalise Date]
),
'Table'[Analysis Date], ASC
)
)
)- NMOORE
Helper II
Hi, Thanks so much for your reply, I was trying to understand summarize and add columns better as I was half-way there but will look at understanding what you did here next week. Thanks again
- lbendlin
Super User
No DAX needs to be harmed for this, You can do this entirely in Power Query. Sort by Analysis Date ascending and then deduplicate by Animals.
- NMOORE
Helper II
Yes, easy in Power Query, already accomplished. The question was for DAX