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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
regnidem
Frequent Visitor

Conditional formatting comparing values across different tables

Hello all,

 

What I'm trying to accomplish:

 

Essentially I'm trying to create a matrix visualization with conditional formatting for the cells.  However, it involves comparing values across different tables.  Creating the matrix is easy; I've already done that.  It's the conditional formatting that I'm having trouble with.

 

I have two tables.  A 'Services' table that has a employee ID, an enounter ID (more than one service can be performed per encounter) and a date (everything has been normalized to the first day of the month).  See spoiler:

 

 

Spoiler
IDEncounter IDYearMonth
1237411/1/2018
1237411/1/2018
1238421/1/2018
1238421/1/2018
1238421/1/2018
1238421/1/2018
1239531/1/2018
1236542/1/2018
1237893/1/2018
1232533/1/2018
4562531/1/2018
4567531/1/2018
4568531/1/2018
4567531/1/2018
4561572/1/2018
4561492/1/2018
4563672/1/2018
4569542/1/2018
4567563/1/2018
4569313/1/2018
7895841/1/2018
7895261/1/2018
7892541/1/2018
7892561/1/2018
7899852/1/2018
7891252/1/2018
7893252/1/2018
7896523/1/2018
7894523/1/2018
7894583/1/2018

 

 

I have a second table that lists the monthly goals for number of encounters for each employee

 

IDGoal
1232
4563
789Ineligible

 

What I need to do is count the number of distinct encounters per employee per month.  Then, if the count of distinct encounters is higher than the goal, highlight that cell.  An approximate visualization using the above data is shown.

 

 ProsGoal.PNG

 

 

What I've done so far:

 

While looking at other threads trying to cobble together a solution, I think I need to create two new measures.  The first counting the  number of distinct encounter IDs per month and the second comparing that count to the goals for each employee.

 

I was able to create the first measure:

 

NumberHours = CALCULATE(
              DISTINCTCOUNT(Services[Encounter ID]), FILTER(Services, Services[YearMonth]
))

I'm stuck on the second measure:

 

GoalMet = CALCULATE(
                  if(Services[NumberHours] > BonusGoals[Goals], 1, 0)
) 

Once I have this measure, I think I can make a conditional formatting statement using the GoalMet measure to highlight the cells, but I'm not positive.

 

Am I on the right track?  Is this something that's possible to accomplish in Power BI?

1 ACCEPTED SOLUTION
MarkLaf
Super User
Super User

Yes, you are on the right track and basically there.

 

I think the main issue is that because you have text in your BonusGoals[Goal] column, it can't be recognized as a number column to compare against number of encounters. I would either remove that row or make the goal null, and change format to number, although the below measure should work with your data as is (IFERROR + VALUE are handling the text):

 

GoalMet = 
CALCULATE(
    VAR CurGoal = IFERROR(VALUE(SELECTEDVALUE(BonusGoals[Goal])),BLANK()) RETURN
    IF([Encounters]>= CurGoal && ISNUMBER(CurGoal),1,0),
    Services
)

 

 

image.png

 

image.png

 

P.S. as @Greg_Deckler also mentions, your NumberHours measure can just be DISTINCTCOUNT(Services[Encounter ID])  -- no need for the calculate or filtering, since the dates and encounter IDs are in the same table so relationship between encouters and dates are implicitly known.

View solution in original post

2 REPLIES 2
MarkLaf
Super User
Super User

Yes, you are on the right track and basically there.

 

I think the main issue is that because you have text in your BonusGoals[Goal] column, it can't be recognized as a number column to compare against number of encounters. I would either remove that row or make the goal null, and change format to number, although the below measure should work with your data as is (IFERROR + VALUE are handling the text):

 

GoalMet = 
CALCULATE(
    VAR CurGoal = IFERROR(VALUE(SELECTEDVALUE(BonusGoals[Goal])),BLANK()) RETURN
    IF([Encounters]>= CurGoal && ISNUMBER(CurGoal),1,0),
    Services
)

 

 

image.png

 

image.png

 

P.S. as @Greg_Deckler also mentions, your NumberHours measure can just be DISTINCTCOUNT(Services[Encounter ID])  -- no need for the calculate or filtering, since the dates and encounter IDs are in the same table so relationship between encouters and dates are implicitly known.

Greg_Deckler
Community Champion
Community Champion

Get rid of the CALCULATE and probably use LOOKUPVALUE to grab your Goal.



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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.