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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Lebowski
New Member

Matrix with rows based on slicer selections AND aggregations

Hoping someone might be able to point me in the right direction ... 

 

I'm trying to produce a matrix that displays the sum of a selected value (from slicer) with subsequent rows showing the sum of 'all' (whole country) and the sum of 'Type' associated with the selection. I've tried to enact a solution posted online and this works well for the selected value and a 'whole country' national total but struggling to show the sum of the 'type' for the selection. Likely going about this in the wrong way, any pointers appreciated! The data format below and workings in this Pbix.

 

What i'm trying to achieve: 

Screenshot 2024-09-02 012414.png

 

 

 

 

 

 

Measures: 

 

Total = Sum(Fact[Count])
Total Count = 
VAR x = SELECTEDVALUE('Rows'[Value])
RETURN
SWITCH(TRUE(),
    x = "Whole Country", [Total](REMOVEFILTERS()),
    x = "Selected",[Total](REMOVEFILTERS(), TREATAS(VALUES('Selector'[Name]), Fact[Name])), 
// x = "Type", ??? not sure how to get this part working // 
    BLANK()
)

 

Fact Table:

idCountName
1223ceddar
2456cherry
3123plumb
4904blossom

Dimensions Table: 

idNameType
1ceddar2
2cherry2
3plumb1
4blossom3

 

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@Lebowski I have so many questions about this but here is your answer. PBIX is attached below signature. First, I have no idea why your made your slicer separate as a disconnected table. Just makes the DAX harder. But, seriously, where on earth did you learn that absolutely bizarre, freakish, and heinous DAX notation? Please, for all that is good and holy, don't write your DAX that way I beg you.

Total Count 1 = 
VAR x = SELECTEDVALUE('Rows'[Value])
VAR __selector = MAX( 'Selector'[Name])
VAR __type = MAXX(FILTER( 'Dimensions', [Name] = __selector ), 'Dimensions'[Type])
VAR __result = SWITCH(TRUE(),
    x = "Whole Country", [Total](REMOVEFILTERS()),
    x = "Selected",[Total](REMOVEFILTERS(), TREATAS(VALUES('Selector'[Name]), Fact[Name])), 
// x = "Type", ??? not sure how to get this part working // 
    SUMX( FILTER( ALL('Fact'), [id] IN SELECTCOLUMNS( FILTER( ALL('Dimensions'), [Type] = __type ), "id", [id] ) ), [Count] )
)
RETURN
  __result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

1 REPLY 1
Greg_Deckler
Community Champion
Community Champion

@Lebowski I have so many questions about this but here is your answer. PBIX is attached below signature. First, I have no idea why your made your slicer separate as a disconnected table. Just makes the DAX harder. But, seriously, where on earth did you learn that absolutely bizarre, freakish, and heinous DAX notation? Please, for all that is good and holy, don't write your DAX that way I beg you.

Total Count 1 = 
VAR x = SELECTEDVALUE('Rows'[Value])
VAR __selector = MAX( 'Selector'[Name])
VAR __type = MAXX(FILTER( 'Dimensions', [Name] = __selector ), 'Dimensions'[Type])
VAR __result = SWITCH(TRUE(),
    x = "Whole Country", [Total](REMOVEFILTERS()),
    x = "Selected",[Total](REMOVEFILTERS(), TREATAS(VALUES('Selector'[Name]), Fact[Name])), 
// x = "Type", ??? not sure how to get this part working // 
    SUMX( FILTER( ALL('Fact'), [id] IN SELECTCOLUMNS( FILTER( ALL('Dimensions'), [Type] = __type ), "id", [id] ) ), [Count] )
)
RETURN
  __result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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