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

Custom Column (Similar to countif in excel) 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
v-henryk-mstf
Community Support
Community Support

Hi @jlys89 ,

 

According to your requirements, I created the corresponding data model according to the data you provided. I did the following test: first, create two columns of column1 and column2 according to the provided conditions, judge whether the rows that meet the requirements are set to 1, and the created Measure is used to count the number of different categories. Finally, the correct result is obtained.

 

v-henryk-mstf_0-1610000276558.png

v-henryk-mstf_1-1610000287321.jpeg

 

Here is the sample pbix file.

 

Best Regards,
Henry

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-henryk-mstf
Community Support
Community Support

Hi @jlys89 ,

 

According to your requirements, I created the corresponding data model according to the data you provided. I did the following test: first, create two columns of column1 and column2 according to the provided conditions, judge whether the rows that meet the requirements are set to 1, and the created Measure is used to count the number of different categories. Finally, the correct result is obtained.

 

v-henryk-mstf_0-1610000276558.png

v-henryk-mstf_1-1610000287321.jpeg

 

Here is the sample pbix file.

 

Best Regards,
Henry

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@jlys89 , Try two new columns like

 

Category 1 = (if [Feature 1] <> null then 1 else 0 + if [Feature 2] <> null then 1 else 0 + if [Feature 3] <> null then 1 else 0 )/3

 

Category 2 = (if [Feature 2] <> null then 1 else 0 + if [Feature 4] <> null then 1 else 0 + if [Feature 6] <> null then 1 else 0 )/3

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.