Forum Discussion
AbhinavJoshi
Responsive Resident
2 years agoGroup By with Conditions
Hi All, I have the following dataset, it has bunch of other columns. I would like to group the data by ID using Power Query. I would like to show the total of amount for the the higest year valu...
- 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! 🤠
AbhinavJoshi
Responsive Resident
2 years agoPlease see expected result
| ID | Latest Year | Total Amount for Latest Year |
| 1 | 2024 | 80 |
| 2 | 2023 | 150 |
| 3 | 2024 | 55 |
| 4 | 2024 | 65 |
| 6 | 2024 | 40 |