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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
Testsubjec
Regular Visitor

Conditional Formatting Based on Previous Period

I'm trying to add conditional formatting based upon the previous peroid via for each Depot ( please see below ).

 

Testsubjec_0-1653927904874.png

 

I tried the below, which seems to bring back the same grand revenue for each period.

 

Test = 
VAR _val =
    CALCULATE (
        SUM(Finance[GrandRevenue])
    )
        - CALCULATE (
          sum(Finance[GrandRevenue]),
            'Calendar'[SagePeriod] = -1 && 'Calendar'[SageYearOffset] = 0 
        )
RETURN
    SWITCH (
        TRUE (),
        _val < 0, -1,
        _val = 0, 0,
        _val > 0, 1
    )

 

 

Any ideas??

 

Thanks.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @Testsubjec ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want.

1. Create a measure as below:

Measure = 
VAR _curperiod =
    SELECTEDVALUE ( 'Finance'[Period] )
VAR _curdepot =
    SELECTEDVALUE ( 'Finance'[Depot] )
VAR _preperiod =
    CALCULATE (
        MAX ( 'Finance'[Period] ),
        FILTER (
            ALLSELECTED ( 'Finance' ),
            'Finance'[Depot] = _curdepot
                && 'Finance'[Period] < _curperiod
        )
    )
VAR _prerevenue =
    CALCULATE (
        SUM ( 'Finance'[GrandRevenue] ),
        FILTER (
            ALLSELECTED ( 'Finance' ),
            'Finance'[Depot] = _curdepot
                && 'Finance'[Period] = _preperiod
        )
    )
RETURN
    IF (
        ISBLANK ( _prerevenue ),
        0,
        IF ( SUM ( 'Finance'[GrandRevenue] ) - _prerevenue > 0, 1, -1 )
    )

2. Use conditional formatting on Values field 

yingyinr_2-1654150182064.png

yingyinr_3-1654150206624.png

In addition, you can refer the following links to get it.

How to Compare the Current Row to the Previous Row Using DAX

How to Compare the Current Row to the Previous Row by Category Using DAX

Use conditional formatting in tables

yingyinr_4-1654150381282.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi  @Testsubjec ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want.

1. Create a measure as below:

Measure = 
VAR _curperiod =
    SELECTEDVALUE ( 'Finance'[Period] )
VAR _curdepot =
    SELECTEDVALUE ( 'Finance'[Depot] )
VAR _preperiod =
    CALCULATE (
        MAX ( 'Finance'[Period] ),
        FILTER (
            ALLSELECTED ( 'Finance' ),
            'Finance'[Depot] = _curdepot
                && 'Finance'[Period] < _curperiod
        )
    )
VAR _prerevenue =
    CALCULATE (
        SUM ( 'Finance'[GrandRevenue] ),
        FILTER (
            ALLSELECTED ( 'Finance' ),
            'Finance'[Depot] = _curdepot
                && 'Finance'[Period] = _preperiod
        )
    )
RETURN
    IF (
        ISBLANK ( _prerevenue ),
        0,
        IF ( SUM ( 'Finance'[GrandRevenue] ) - _prerevenue > 0, 1, -1 )
    )

2. Use conditional formatting on Values field 

yingyinr_2-1654150182064.png

yingyinr_3-1654150206624.png

In addition, you can refer the following links to get it.

How to Compare the Current Row to the Previous Row Using DAX

How to Compare the Current Row to the Previous Row by Category Using DAX

Use conditional formatting in tables

yingyinr_4-1654150381282.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

amitchandak
Super User
Super User

@Testsubjec , Period should be part of separate table having period , year period or year period rank

 

example

 


Period Rank = RANKX(all(Period),Period[year period],,ASC,Dense)

 


This Period = CALCULATE(sum('Table'[Qty]), FILTER(ALL(Period),Period[Period Rank]=max(Period[Period Rank])))
Last Period = CALCULATE(sum('Table'[Qty]), FILTER(ALL(Period),Period[Period Rank]=max(Period[Period Rank])-1))

 

 

you can use period in place of period rank

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

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.

Top Solution Authors