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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Solution Sage
Solution Sage

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
Solution Sage
Solution Sage

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
Super User
Super User

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


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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