Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now
Hello,
I have test data like this:
NOTE: you can download pbix file here.
Scenario:
Users are being interviewed and it is possible that the same user gets interviewed multiple times during a month.
Users are providing Yes/No answers (represented by 1 and 0, respectively) in a questionnaire that has multiple questions.
Requirement:
Matrix should display all results for interviews that occured in the selected month, regardless how many questionnaires were submitted.
However, in TOTAL column we need to count how many users answered with Yes on certain question, but using only the latest response. (If there are muliple answers by same users, previos responses should be ignored in the calculation).
So, in the example below, expected Total in the first row should be 2 and in the second row it should be 0.
Please help!
Solved! Go to Solution.
Hi, @nenadpekec
Please check the below picture and the sample pbix file's link down below.
Hi, My name is Jihwan Kim.
If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.
Linkedin: linkedin.com/in/jihwankim1975/
Twitter: twitter.com/Jihwan_JHKIM
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Hi, @nenadpekec
Please check the below picture and the sample pbix file's link down below.
Hi, My name is Jihwan Kim.
If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.
Linkedin: linkedin.com/in/jihwankim1975/
Twitter: twitter.com/Jihwan_JHKIM
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Thank you, very much!
// This measure shows how many users
// answered 'Yes' to at least one question
// (and this 'Yes' must be the latest
// answer).
// **Everything is relative to
// the current context, of course.**
// So, if you slice by Question, User and
// Date, you'll replicate the matrix you've
// shown but also the totals will be according
// to your definition.
[Your Measure] =
// We want to count the users whose
// latest answer is 'Yes' to at least
// one question in scope.
var UserQuestionWithLatestResponseDate =
ADDCOLUMNS(
SUMMARIZE(
T,
T[User],
T[Question]
),
"@LatestResponseDate",
CALCULATE( MAX( T[Date] ) )
)
var CountOfUsersWithAtLeastOneQWithYesA =
CALCULATE(
DISTINCTCOUNT( T[User] ),
TREATAS(
UserQuestionWithLatestResponseDate,
T[User],
T[Question],
T[Date]
),
KEEPFILTERS( T[Value] = 1 )
)
return
CountOfUsersWithAtLeastOneQWithYesA + 0
It wolud be equally as easy to write a measure which would count users with all questions (in scope) answered with "Yes." And if you sliced such a measure the way the matrix is, the outcome would be the same as for the measure above.
Please bear in mind the definition of the measure when you view the measure's values. The measure is correct and does what you want but you have to read well its description to realize it's doing what it's supposed to. One last screenshot:
Check out the October 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
33 | |
15 | |
14 | |
12 | |
9 |