Forum Discussion
Anonymous
4 years agoNot applicable
Add new column with IF-ELSE condition in Power Query
I have table as the one on the left below and would like to transform into the one on the right based on the following condition: If MTH is 9,10 or 11, sum all the PRICE (SUM all PRICE for MTH 9,...
- 4 years ago
Hi Anonymous ,
Here are the pics, might by in reverse order.Groupby to get your sums, then divide by 12 to get your division, the use conditional col to decide which col to use. Then delete intermediate columns.
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel
ronrsnfld
4 years agoSuper User
You can do this all in a single aggregation within the Table.Group function:
let
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{
{"ACT/FC", type text}, {"MTH", Int64.Type}, {"TYPE", type text}, {"PRICE", Int64.Type}}),
group = Table.Group(#"Changed Type","MTH",{
"PRICE", each
if List.Contains({9..11},[MTH]{0})
then List.Sum([PRICE])
else List.Sum([PRICE])/12, type number
})
in
group