March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
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 |
North | Yes |
South | No |
North | Null |
West | Yes |
South | No |
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 | |
North | 50 |
South | 30 |
East | 75 |
West | 30 |
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
Solved! Go to Solution.
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
// 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
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
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
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
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
23 | |
16 | |
12 | |
9 | |
7 |
User | Count |
---|---|
38 | |
32 | |
29 | |
12 | |
11 |