cancel
Showing results 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.

Anonymous
Not applicable

## Percentage of Column

New to DAX here and I am having trouble with a formula. IF I have one column like below how could I calculate the the count of Y by the total count of All.  So I would like to calculate that the selected value by the total value. ( 1 Yes)/ (4) = .25

 Column Name: Y/N Y N N N
1 ACCEPTED SOLUTION
Helper II

A few ways to do this, one of which is creating 3 separate measures:

M_TOTAL = COUNT(Table[Column])

M_YES = CALCULATE ( COUNT(Table[Column]) , Table[Column] = "Y" )

M_YES_PERCENT = DIVIDE ( [M_YES] , [M_TOTAL] )

3 REPLIES 3
Community Support

Hi @Anonymous ,

You can create a measure as below:

``````Measure =
var a =CALCULATE(COUNTROWS('Table'),FILTER(ALL('Table'),'Table'[Column Name: Y/N]="Y"))
var b=COUNTROWS(ALL('Table'))
Return
IF(MAX('Table'[Column Name: Y/N])="Y",DIVIDE(a,b),BLANK())``````

You can just return :  DIVIDE(a,b) , but if you just wanna show the rows which contain "Y",use the measure above,and you will see:

Or you can create a calculated column as below:

``````Column =
var a =CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Column Name: Y/N]="Y"))
Return
IF('Table'[Column Name: Y/N]="Y",DIVIDE(a,COUNTROWS('Table')),BLANK())``````

And you will see:

Best Regards,
Kelly
Super User

@Anonymous

% = divide(count(Table[Column], Table[Column]="Y"),count(Table[Column]))

OR
% = divide(count(Table[Column], Table[Column]="Y"),calculate(count(Table[Column]),allselected(Table)))

Helper II

A few ways to do this, one of which is creating 3 separate measures:

M_TOTAL = COUNT(Table[Column])

M_YES = CALCULATE ( COUNT(Table[Column]) , Table[Column] = "Y" )

M_YES_PERCENT = DIVIDE ( [M_YES] , [M_TOTAL] )

Announcements

#### 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

#### Power BI Monthly Update - April 2024

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

#### Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors