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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
adavid999
Helper V
Helper V

dax for % answering YES in column

Apols for this simple question - i have been away from Dax for a few weeks and can't figure out, but I would like to convert table below:

 

Q1
NorthYes
SouthNo
North

Null

WestYes
SouthNo

to show the percent of Yes for each region. Like a crosstab in spss but just % answering yes for each question and aggregated by region. It would ideally look something like:

 

 Q1 % answering Yes
North50
South30
East75
West30

Is there an easy way to do this? I managed myself using 3 different measures to come up with % Yes (e.g. count yes, count no, sum yes+no, % yes is no yes/total), but I have around 50 questions (so wld require 150 measures) and was wondering if there is a quicker way. I.e. is there one measure I can do per column to capture % yes?

 

Many thanks,

A

 

 

 

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @adavid999 

I understand the responses are in a different column for each question, correct? If so, you should unpivot the columns in the query editor, so that you have one column with the answer, one with the region and one with the question number. Once you've done than, you can do what you need with just one measure.

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs

Cheers 

SU18_powerbi_badge

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

// Table structure:
// Region | Question | Answer
// A	  | Q1		 | Yes
// B	  | Q1       | No
// A      | Q2       | (Blank)
// ...

// Having the above, you can create
// your measure that will calculate
// the % of "Yes" in any selection
// of regions and questions.

[% Yes] =
var __yesCount =
	CALCULATE(
		COUNTROWS( T ),
		KEEPFILTERS( T[Answer] = "Yes" )
	)
var __totalCount = COUNTROWS( T )
var __result =
	DIVIDE( 
		__yesCount,
		__totalCount
	)
return
	__result

 

The above measure takes into account all the answers, even (blank)'s. If you want to ignore (blank)'s, then this measure will do it:

 

// Table structure:
// Region | Question | Answer
// A	  | Q1		 | Yes
// B	  | Q1       | No
// A      | Q2       | (Blank)
// ...

// Having the above, you can create
// your measure that will calculate
// the % of "Yes" in any selection
// of regions and questions.

[% Yes] =
var __yesCount =
	CALCULATE(
		COUNTROWS( T ),
		KEEPFILTERS( T[Answer] = "Yes" )
	)
var __totalCount = 
	CALCULATE(
		COUNTROWS( T ),
		KEEPFILTERS(
			NOT ISBLANK( T[Answer] )
		)
	)
var __result =
	DIVIDE( 
		__yesCount,
		__totalCount
	)
return
	__result

 

Best

D

AlB
Community Champion
Community Champion

Hi @adavid999 

I understand the responses are in a different column for each question, correct? If so, you should unpivot the columns in the query editor, so that you have one column with the answer, one with the region and one with the question number. Once you've done than, you can do what you need with just one measure.

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs

Cheers 

SU18_powerbi_badge

 

Thank you @AlB I will try this. I am working in excel power pivot and it seems there is less functionality compared to power query but I will hunt around

AlB
Community Champion
Community Champion

@adavid999 

You have Power Query in Excel too. And it certaily has the functionality to pivot/unpivot columns

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs

Cheers 

SU18_powerbi_badge

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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