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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
EricCantona
New Member

Use of DAX measure in Matrix visual - how to ignore filters within each cell

I'm trying to develop a measure that will analyse, dynamically, the following data table:

NameTypeSeverityYear
AnnaCold12020
AnnaCold12020
AnnaCold22021
AnnaCold12021
BrianFlu22021
BrianFlu12021
CarolCold32020
CarolFlu12020
DaveFlu12020
EricCold12020
EricCold22021
FredFlu32020


The behaviour I am looking for a matrix table that shows the maximum 'severity' for each 'name' and 'type'. For example  So for example Anna had 4 colds, one with maximum severity 2, so she would count as one in the 'Cold', severity=2 cell, but not in the severity = 1 cell.

I have tried generating a measure to do this as I want the table to be affected by slicers on the report e.g. by selecting individual years. So the expected result would be as follows for all years:

 Max Severity by Name 
Type123Total
Cold0213
Flu2114
Total2326

Whereas when selection for year 2020 then you'd get the following:

 Max Severity by Name 
 123Total
Cold2013
Flu2013
Total4025


The approach I initially tried in the DAX measure is to generate a variable with the Max(Severity) by Name and Type (for which I generate a calculated column 'name_type' which is a concat

 

 

enation of the two columns)  and then tried to count a distinctcount on the number of names that match the Max(Severity) for each type. 

 

Max Severity count = 
VAR MaxSev =
	CALCULATE(
        MAX('events'[Severity]),
        ALLEXCEPT('events','events'[name_type])
)
VAR CurrType =
	CALCULATE(
        MAX('events'[Type]),
        ALLEXCEPT('events','events'[name_type])
)
RETURN
    Max(calculate(
        DISTINCTCOUNT('events'[Name]) ,  FILTER ('events', AND('events'[Severity]=MaxSev,'events'[Type]=CurrType)
    )),0)
​

 

 

 

Which gives me this:

EricCantona_1-1711461050844.png

Any ideas on how I can alter the measure to give the expected table? I appreciate I may have to have a second measure with a If Hasonefilter calculation in to get the totals to work, but if I can get the main table working, that would be a start.




1 ACCEPTED SOLUTION
EricCantona
New Member

I think that is pretty close.
I've not used the summarize function before but it seems to simplify the eventual filtering.

The only issue was that the column and overall totals were not correct. If there was a single 'name' with the same max 'severity' for two different 'types' then it got counted twice. So I altered the code so it does a second summarize based on the 'name' before counting rows. (I also added the max function to report 0 rather than blank).

Max Severity count =
VAR maxtab=
FILTER (
SUMMARIZE ( 'events', 'events'[Type], 'events'[Name], 'events'[Severity] ),
'events'[Severity] = CALCULATE ( MAX ( 'events'[Severity] ), ALL ( 'events'[Severity] ) )
)
return
 MAX(COUNTROWS(SUMMARIZE(maxtab,[Name])),0)

I think this works now.
 


View solution in original post

4 REPLIES 4
EricCantona
New Member

I think that is pretty close.
I've not used the summarize function before but it seems to simplify the eventual filtering.

The only issue was that the column and overall totals were not correct. If there was a single 'name' with the same max 'severity' for two different 'types' then it got counted twice. So I altered the code so it does a second summarize based on the 'name' before counting rows. (I also added the max function to report 0 rather than blank).

Max Severity count =
VAR maxtab=
FILTER (
SUMMARIZE ( 'events', 'events'[Type], 'events'[Name], 'events'[Severity] ),
'events'[Severity] = CALCULATE ( MAX ( 'events'[Severity] ), ALL ( 'events'[Severity] ) )
)
return
 MAX(COUNTROWS(SUMMARIZE(maxtab,[Name])),0)

I think this works now.
 


EricCantona
New Member

Hi Tamerj1
Is there a typo in your formulas? For the definition of VAR T3, you use T3 - should this be T2?

When I tried it with T3 being defined from T2, then I get the following matrix...

EricCantona_0-1711485255236.png

Thanks

.

@EricCantona 

You are right. Typo mistake and wrong approach as well. Let's try

Max Severity count =
COUNTROWS (
FILTER (
SUMMARIZE ( 'events', 'events'[type], 'events'[name], 'events'[Severity] ),
'events'[Severity] = CALCULATE ( MAX ( 'events'[Severity] ), ALL ( 'events'[Severity] ) )
)
)

tamerj1
Super User
Super User

Hi @EricCantona 

please try

Max Severity count =
VAR T1 =
SUMMARIZE ( 'events', 'events'[name], 'events'[Severity] )
VAR T2 =
CALCULATETABLE (
SUMMARIZE ( 'events', 'events'[name], 'events'[Severity] ),
ALL ( 'events'[Severity] )
)
VAR T3 =
TOPN ( 1, T3, 'events'[Severity] )
VAR T4 =
INTERSECT ( T1, T3 )
VAR Result =
COUNTROWS ( T4 )
RETURN
Result

 

or

 

Max Severity count =
SUMX (
SUMMARIZE ( 'events', 'events'[type], 'events'[Severity] ),
VAR T1 =
CALCULATETABLE ( SUMMARIZE ( 'events', 'events'[name], 'events'[Severity] ) )
VAR T2 =
CALCULATETABLE (
SUMMARIZE ( 'events', 'events'[name], 'events'[Severity] ),
ALL ( 'events'[Severity] )
)
VAR T3 =
TOPN ( 1, T3, 'events'[Severity] )
VAR T4 =
INTERSECT ( T1, T3 )
VAR Result =
COUNTROWS ( T4 )
RETURN
Result
)

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors