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

Did you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now

Reply
Anonymous
Not applicable

Matrix Conditional Formatting (with Hierarchy)

Hi there,

 

I've created a matrix below that shows frequency of visit by animal (Rows) and clinic (Columns). I would like to conditional format the individual frequencies based on whether they are above or below the overall frequency.

For example, overall cat visits is 4.5. So Clinic C should be in green because 5.0>4.5. Clinics A & B should be in red because it is lower than 4.5
EL1988_0-1625561694606.png

I calculated frequency using this created measure: 

Freq per day = Divide(CALCULATE(COUNTROWS(Sheet1)),CALCULATE(DISTINCTCOUNT(Sheet1[Day]),ALL(Sheet1[Type],Sheet1[Color])),0)

 

The data source looks like this (apologies I was unable to attach my excel & pbix file):

DayClinicTypeColor
1ADogBrown
1BDogBrown
1BDogBrown
2ADogWhite
2BDogWhite
2CCatGrey
3BCatGrey
3CCatGrey
4ACatBlack
4ACatBlack
4CCatBlack
4CCatBlack
4CCatBlack
4CCatBlack
4CCatBlack
4CCatBlack
4CCatBlack
4CCatBlack
4CCatBlack
4CCatBlack
4CCatBlack
4CCatBlack
4CCatBlack

 

Thank you in advance.

 

 

1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hi @Anonymous ,

 

Create 3 measures as below:

_total = DIVIDE(CALCULATE(COUNTROWS('Sheet1'),FILTER(ALL(Sheet1),'Sheet1'[Type]=MAX('Sheet1'[Type]))),CALCULATE(DISTINCTCOUNT(Sheet1[Day]),ALL(Sheet1)))
Measure = 
var _num=CALCULATE(COUNTROWS('Sheet1'),FILTER(ALL(Sheet1),'Sheet1'[Type]=MAX('Sheet1'[Type])&&'Sheet1'[Clinic]=MAX('Sheet1'[Clinic])))+0
var _deno=CALCULATE(DISTINCTCOUNT(Sheet1[Day]),FILTER(ALL(Sheet1),'Sheet1'[Type]=MAX('Sheet1'[Type])))
Return
IF(ISINSCOPE(Sheet1[Clinic]),DIVIDE(_num,_deno),BLANK())
Measure 2 = IF(ISBLANK('Sheet1'[Measure]),BLANK(), IF('Sheet1'[Measure]<[_total],"#FF3349","#151314"))

And you will see:

vkellymsft_0-1625730540124.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

View solution in original post

2 REPLIES 2
v-kelly-msft
Community Support
Community Support

Hi @Anonymous ,

 

Create 3 measures as below:

_total = DIVIDE(CALCULATE(COUNTROWS('Sheet1'),FILTER(ALL(Sheet1),'Sheet1'[Type]=MAX('Sheet1'[Type]))),CALCULATE(DISTINCTCOUNT(Sheet1[Day]),ALL(Sheet1)))
Measure = 
var _num=CALCULATE(COUNTROWS('Sheet1'),FILTER(ALL(Sheet1),'Sheet1'[Type]=MAX('Sheet1'[Type])&&'Sheet1'[Clinic]=MAX('Sheet1'[Clinic])))+0
var _deno=CALCULATE(DISTINCTCOUNT(Sheet1[Day]),FILTER(ALL(Sheet1),'Sheet1'[Type]=MAX('Sheet1'[Type])))
Return
IF(ISINSCOPE(Sheet1[Clinic]),DIVIDE(_num,_deno),BLANK())
Measure 2 = IF(ISBLANK('Sheet1'[Measure]),BLANK(), IF('Sheet1'[Measure]<[_total],"#FF3349","#151314"))

And you will see:

vkellymsft_0-1625730540124.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

amitchandak
Super User
Super User

@Anonymous , at type level

M1  = Divide(CALCULATE(COUNTROWS(Sheet1)),CALCULATE(DISTINCTCOUNT(Sheet1[Day]),ALLexpect(Sheet1 , Sheet1[Type])),0)

 

at type color level

 M2 = Divide(CALCULATE(COUNTROWS(Sheet1)),CALCULATE(DISTINCTCOUNT(Sheet1[Day]),ALLexpect(Sheet1 , Sheet1[Type],Sheet1[Color])),0)

 

if You need to create a color measure if want both the 1 and 2 formula I suggested for color, then you need to use isinscope

 

like

Switch (true(),

isinscope(Table[Tyep])  && not(isinscope (Table[Color])) && [frequency per day] > [M1]  , "red" ,

// add other condition

"green"

)

 

Use this in conditional formatting using field value option

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.