0
votes

I need direction or exact formula help in power query. I am trying to calculate the sum of columns if condition is true, and bringing the result in new column. The code is Below;

({If [Num] = 1 Then  Sum([Column1](Value),[Column3](Value)}),  

If Column(Num) equlas 1 then add values in column1 and 3 If Column(Num) = 2 then add values in column2 and column3 Maybe I need to use GroupBy...

In brief what I want to do is use sumif in excel

enter image description here

1
You are trying to sum all column or just a few of then ? And under what condition? For example sum all other columns when column3=1; sum column12 when (column3=1 or column12=1) - horseyride
Sum column12 and column9 if Column3 is equal to 1 - user16316847
Please show example of data input and desired output. It is not clear if you want to sum just the value on a given row (=if [Column3] = 1 then [Column9] + [Column12] else null), a running conditional total, fill every cell in the column with the conditional total, or exactly what. - Ron Rosenfeld
@RonRosenfeld Look above I have added similar visual, and changed the question. In brief, I want to use SumIf of Excel in PowerQuery - user16316847
I don't see your desired output. - Ron Rosenfeld

1 Answers

1
votes

Based on your original question and the comments, it appears you only want to add the numbers in the same row under certain conditions of column 3 (or Num in your revised question).

Try:

=if [Column3] = 1 then [Column9] + [Column12] else null

or, in native M-Code:

#"Added Custom" = Table.AddColumn(#"Changed Type", "New Column Name", each if [Column3] = 1 then [Column9] + [Column12] else null)