Forum Discussion
Group By with Conditions
- 2 years ago
output
dax calculated table :
Table 2 = var ds = ADDCOLUMNS( ADDCOLUMNS( SUMMARIZE( Table4, Table4[ID] ), "max year" , CALCULATE(MAX(Table4[year])) ), "total amount" , var maxyear = [max year] RETURN CALCULATE(SUM(Table4[Amount]) , Table4[year] =maxyear )) return dslet me know if this helps .
If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution ✅
It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠 - 2 years ago
output
let Source = Table4, Grouped = Table.Group(Source, {"ID", "Year"}, {{"Total Amount", each List.Sum([Amount]), type number}}), MaxYear = Table.Group(Grouped, {"ID"}, {{"MaxYear", each List.Max([Year]), type number}}), Result = Table.Join(MaxYear, {"ID", "MaxYear"}, Grouped, {"ID", "Year"}), FinalResult = Table.SelectColumns(Result, {"ID", "Year", "Total Amount"}) in FinalResultlet me know if this helps .
If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution ✅
It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠
Thank you Daniel29195. Would it be possible to achive the same in Power Query, the reason I'm asking because I'm doing a lot of other modelling there and have other columns that I would like to keep as well.
output
let
Source = Table4,
Grouped = Table.Group(Source, {"ID", "Year"}, {{"Total Amount", each List.Sum([Amount]), type number}}),
MaxYear = Table.Group(Grouped, {"ID"}, {{"MaxYear", each List.Max([Year]), type number}}),
Result = Table.Join(MaxYear, {"ID", "MaxYear"}, Grouped, {"ID", "Year"}),
FinalResult = Table.SelectColumns(Result, {"ID", "Year", "Total Amount"})
in
FinalResult
let me know if this helps .
If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution ✅
It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠