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
PBI_Curve
Helper I
Helper I

Conditional Formatting - One Date's Values Based Another Date's Value

Hi Guys,

 

I'm creating a fairly basic table listing sales totals per salesperson, over time - as below. There are 3 fields: Date, Sales and Salesperson, that make up this table.

 

What I would like to do is colour code increases/decreases/no changes on the most recent date's total based off the previous date's total.

 

 01-Jan02-Jan
Tom £  800.00 £  700.00
Jane £  400.00 £  400.00
Mary £           -   £  150.00
John £  200.00 £  150.00
Luke £  650.00 £  800.00

 

So for example, the above would be [coloured] as below:

 

 01-Jan02-Jan
Tom £  800.00 £700.00 [RED] 
Jane £  400.00 £400.00 [YELLOW] 
Mary £           -   £150.00 [GREEN} 
John £  200.00 £150.00 [RED] 
Luke £  650.00 £800.00 [GREEN] 

 

 

I can only seem to apply conditional formatting to all values (i.e. both columns) on a general highest/lowest scale.

 

Is it possible to do what I'm looking for?

 

 

Cheers.

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

Hi @PBI_Curve,

 

I'd like to suggest you write a measure to calculate the diff between date and return color string based on result, then you can simply use above measure as conditional format field of value column.

Measure = 
VAR currPerson =
    SELECTEDVALUE ( 'Table'[Person] )
VAR currDate =
    MAX ( 'Table'[Date] )
VAR prevDate =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER ( ALLSELECTED ( 'Table' ), [Date] < currDate )
    )
VAR diff =
    LOOKUPVALUE (
        'Table'[Amount],
        'Table'[Person], currPerson,
        'Table'[Date], currDate
    )
        - LOOKUPVALUE (
            'Table'[Amount],
            'Table'[Person], currPerson,
            'Table'[Date], prevDate
        )
RETURN
    IF ( diff > 0, "Green", IF ( diff = 0, "Orange", "Red" ) )

13.png

 

Regards.

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

Hi @PBI_Curve,

 

I'd like to suggest you write a measure to calculate the diff between date and return color string based on result, then you can simply use above measure as conditional format field of value column.

Measure = 
VAR currPerson =
    SELECTEDVALUE ( 'Table'[Person] )
VAR currDate =
    MAX ( 'Table'[Date] )
VAR prevDate =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER ( ALLSELECTED ( 'Table' ), [Date] < currDate )
    )
VAR diff =
    LOOKUPVALUE (
        'Table'[Amount],
        'Table'[Person], currPerson,
        'Table'[Date], currDate
    )
        - LOOKUPVALUE (
            'Table'[Amount],
            'Table'[Person], currPerson,
            'Table'[Date], prevDate
        )
RETURN
    IF ( diff > 0, "Green", IF ( diff = 0, "Orange", "Red" ) )

13.png

 

Regards.

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

@v-shex-msft worked a charm.

Thanks!

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.