Forum Discussion
awais692
Jul 26, 2021Copper Contributor
Count if formula for multiple columns in power query
How to write a formula =countif(A2:M2,"<=15") in power query?
11 Replies
Sort By
If you mean to countif() each row of the table, as variant
- add Index column starting from 0
- add custom column with formula
=List.Accumulate(Record.ToList(#"Added Index"{[Index]}),0, (s,c) => s+Number.From(c<= 15))
- balajimaikandanCopper Contributor
SergeiBaklan can you show an example or any screenshot from power query
That could be done in more correct way. Let say we have such table
On the right is result of COUNTIF().
Within Power Query we may do same count by
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], countif = Table.AddColumn( Source, "count", each List.Count( List.Select( Record.FieldValues(_), each _ <=15 ) ) ) in countif
If do step by step, not within one formula for new column
1) Add column Values which contains list of all values for the current row
2) Add another column Select which selects from each list above only values which meet condition
3) Count number of values in each list:
4) Remove intermediate columns
In above I didn't care about errors handling and types assignments which highly recommended to do in real projects. Simplest from above is manually adding type in formula bar when you create custom column, i.e. add manually 4th parameters like
Please check above sample in attached file.