Forum Discussion
Matrix, custom calculation in Total Column
- 5 years ago
Hi, nenadpekec
Please check the below picture and the sample pbix file's link down below.
Values Latest Measure =VAR currentq =MAX ( 'Table'[Questions] )VAR currentuser =MAX ( 'Table'[User] )VAR latestdate =CALCULATE (MAX ( 'Table'[Date] ),FILTER (ALLSELECTED ( 'Table' ),'Table'[Questions] = currentq&& 'Table'[User] = currentuser))RETURNCALCULATE (SUM ( 'Table'[Value] ),FILTER (ALLSELECTED ( 'Table' ),'Table'[Questions] = currentq&& 'Table'[User] = currentuser&& 'Table'[Date] = latestdate))Values Latest Measure Total Fix =IF (ISFILTERED ( 'Table'[Date] ),SUM ( 'Table'[Value] ),SUMX ( VALUES ( 'Table'[User] ), [Values Latest Measure] ))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
// 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: