Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
jlys89
Frequent Visitor

PowerQuery Countifs across multiple columns

Hi 

 

I'm trying to figure out how to the do the following in PowerQuery (M) for Power BI where I want to add 2 additional columns to my data set as seen below:

What i want to achieve is counting the amount of times that a given feature is procent in the columns Feature 1 - Feature 6 where features are grouped into categories. (The 2 custom columns i need - Category 1 and Category 2)

 

Category 1: Feature 1, Feature 3, Feature 5

Category 2: Feature 2, Feature 4, Feature 6

 

For ID 1 the prefered method would be a count of: 3 because Feature 1, Feature 3 and Feature 5 is present in the 6 columns.

Afterwards I want to devide this by the total number of features meaning we get:

 

Category 1: 3/3 = 1,00 or 100 %

Category 2: 0/3 = 0  or 0 %

 

IDFeature 1Feature 2Feature 3Feature 4Feature 5Feature 6FeaturesCategory 1Category 2
1Feature 1nullFeature 3nullFeature 5null310
2nullnullFeature 3nullFeature 5Feature 630,6666666670,33
3nullnullFeature 3nullFeature 5Feature 630,6666666670,33
4nullFeature 2nullFeature 4nullnull200,67
5nullnullnullFeature 4nullnull10

0,33

 

Any help would be much appreciated 🙂

1 ACCEPTED SOLUTION
jlys89
Frequent Visitor

Thanks. I ended up finding this article that solved the problem 🙂 Thanks alot for the contributions though 🙂

 

https://community.powerbi.com/t5/Power-Query/Multiple-CountIf-function-in-Power-Query/m-p/1321475

View solution in original post

3 REPLIES 3
jlys89
Frequent Visitor

Thanks. I ended up finding this article that solved the problem 🙂 Thanks alot for the contributions though 🙂

 

https://community.powerbi.com/t5/Power-Query/Multiple-CountIf-function-in-Power-Query/m-p/1321475

mahoneypat
Microsoft Employee
Microsoft Employee

This is doable in query, but is much better done by unpivoting your data and then using a DAX measure.

 

For example, here is a formula that will generate your Category 1 column in the query editor.  Put it in a custom column.

 

= let thisrecordlist = Record.ToList(_) in List.Count(List.Select(List.Transform({1,3,5}, each thisrecordlist{_}), each Text.Contains(_, "Feature")))/3

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Hi Pat,
Thanks alot of taking the time. Any chance you can explain how this part functions (List.Transform({1,3,5} I'm currently getting an error when utilizing your formula and I think it might be due to these columns being part of a bigger table.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.