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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
HassanMoosa
Helper I
Helper I

DAX query to find percentage of few categories within column

Hi, can anyone guide me an efficient BI DAX Query to find percentage of only two categories like in my case I want to take percentage of 1 and 2 out of 1-5 scale rating ignoring the missing values in the column, rest all data set to be included. 

 

e.g.: Poor Feedback % = 1(category) + 2(category) / Out of all data set "Excluding missing values" * 100

 

Below is the screenshot of my likert scale and column name. 

 

BL Numeric.PNG

1 ACCEPTED SOLUTION
Mohammad_Refaei
Solution Specialist
Solution Specialist

You can use something like:

Poor Feedback% =
DIVIDE (
    CALCULATE ( COUNTROWS ( 'Table_Name' ), [BL_Numeric] IN { 1, 2 } ),
    CALCULATE ( COUNTROWS ( 'Table_Name' ), [BL_Numeric] <> BLANK () )
) * 100

View solution in original post

8 REPLIES 8
Mohammad_Refaei
Solution Specialist
Solution Specialist

You can use something like:

Poor Feedback% =
DIVIDE (
    CALCULATE ( COUNTROWS ( 'Table_Name' ), [BL_Numeric] IN { 1, 2 } ),
    CALCULATE ( COUNTROWS ( 'Table_Name' ), [BL_Numeric] <> BLANK () )
) * 100

Hi @Mohammad_Refaei  i tried with your query but value is exceding above thousands.  As it should be not greater then 100% i think something is worng while evaluating the expression. 

Thanks @Mohammad_Refaei for the guidance.  Can you please explain the usage of  "<>BLANK ( )" in the second line?

Most welcome Hassan.... The division by <> BLANK() beacause you want to ignore missing values.

 

If the measure is reporting high values then we can be more strict and ignore any other filters like this:

 

Poor Feedback% =
DIVIDE (
    CALCULATE ( COUNTROWS ( ALL('Table_Name') ), [BL_Numeric] IN { 1, 2 } ),
    CALCULATE ( COUNTROWS ( ALL('Table_Name') ), [BL_Numeric] <> BLANK () )
) * 100

 

@Mohammad_Refaei thanks alot for your time and sharing tips.  It's working perectly fine now!

My pleasure @HassanMoosa 

amitchandak
Super User
Super User

@HassanMoosa , Measure in one of three ways

 

divide(countrows(filter(Table, Table[Category] in {1,2})), countrows(filter(Table, nor(isblank(Table[Category])))))

 

divide(countrows(filter(Table, Table[Category] in {1,2})), countrows(filter(allselected(Table), nor(isblank(Table[Category])))))

 

 

divide(countrows(filter(allselected(Table), Table[Category] in {1,2})), countrows(filter(allselected(Table), nor(isblank(Table[Category])))))

Hi @amitchandak  thanks for your inputs.  I tried with your last query but I am facing error that "nor" is not a function.  I tried with false e.g.: 

FALSE(Combine_Feedback[OLE_Numeric]) but this line shows error unexpected parameter.  Thanks for your kind time. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors