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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Maieev
Resolver I
Resolver I

Conditional formatting based on formula - previousyear calculation

Hi guys,

 

I have a table - Sales, where I have Actual ASP and Revenue columns. I wrote a formula to be able to show conditional formatting - icons based on the difference between years. It works for Revenue but doesn't for Actual ASP. They are in the same table, with the same dates. The only difference is that in column Revenue there are no blanks, and in Actual ASP blanks are possible and they are there.

Measure that works:

 

Icon Revenue = 
VAR _val =
 CALCULATE ( SUM ( Sales[Revenue] ) ) 
 -
 CALCULATE ( SUM ( Sales[Revenue] ),
        PREVIOUSYEAR ( Sales[Date] ), ALL(Sales) )
        
RETURN
    IF (
        ISBLANK ( _val ) || SELECTEDVALUE('Sales'[Time.Fiscal Year Name]) = "21/22",
        BLANK (),  -- If previous year's data is not available or it's for 21/22 fiscal year, return blank to turn off conditional formatting
        SWITCH (
            TRUE (),
            _val < 0, -1, 
            _val = 0, 0,
            _val > 0, 1
        )
    )

 


And that doesn't work:

 

Icon ASP = 
VAR _val =
    CALCULATE ( SUM ( Sales[Actual ASP] ) ) 
    -
    CALCULATE (
        SUM ( Sales[Actual ASP] ),
           PREVIOUSYEAR ( Sales[Date] ), ALL(Sales) )
        
RETURN
    IF (
        ISBLANK ( _val ) || SELECTEDVALUE('Sales'[Time.Fiscal Year Name]) = "21/22",
        BLANK (),  -- If previous year's data is not available or it's for 21/22 fiscal year, return blank to turn off conditional formatting
        SWITCH (
            TRUE (),
            _val < 0, -1, 
            _val = 0, 0,
            _val > 0, 1
        )
    )

 

 

I also tried to connect that to calendar table and take date from there but still no result. I broke down formula and wanted to check that PreviousYear calculation but it doesn't show results in the table:

 

PreviousYearASP = 
CALCULATE (
    SUM ( Sales[Actual ASP] ),
    PREVIOUSYEAR ( Sales[Date] )
)

 

Maieev_0-1707989070146.png

As you can see there are values. I don't know why one measure works and the other just with column name changed not. Their format in the table is exactly the same.

 

Could you please help with some ideas?

 

1 ACCEPTED SOLUTION
Maieev
Resolver I
Resolver I

I've managed to figure it out!

 

I needed to use SAMPERIODLASTYEAR function and use it with separate Calendar Year - also in the visualization I changed the Year field to the one from the Calendar table.

 

Icon Revenue = 
VAR _val =
 CALCULATE ( SUM ( Sales[Revenue] ) ) 
 -
CALCULATE (
    SUM ( Sales[Revenue] ),
    SAMEPERIODLASTYEAR( ( 'Calendar'[Date] )
))
        
RETURN
    IF (
        ISBLANK ( _val ) || SELECTEDVALUE('Sales'[Time.Fiscal Year Name]) = "21/22",
        BLANK (),  -- If previous year's data is not available or it's for 21/22 fiscal year, return blank to turn off conditional formatting
        SWITCH (
            TRUE (),
            _val < 0, -1, 
            _val = 0, 0,
            _val > 0, 1
        )
    )

 

It works great :).

View solution in original post

1 REPLY 1
Maieev
Resolver I
Resolver I

I've managed to figure it out!

 

I needed to use SAMPERIODLASTYEAR function and use it with separate Calendar Year - also in the visualization I changed the Year field to the one from the Calendar table.

 

Icon Revenue = 
VAR _val =
 CALCULATE ( SUM ( Sales[Revenue] ) ) 
 -
CALCULATE (
    SUM ( Sales[Revenue] ),
    SAMEPERIODLASTYEAR( ( 'Calendar'[Date] )
))
        
RETURN
    IF (
        ISBLANK ( _val ) || SELECTEDVALUE('Sales'[Time.Fiscal Year Name]) = "21/22",
        BLANK (),  -- If previous year's data is not available or it's for 21/22 fiscal year, return blank to turn off conditional formatting
        SWITCH (
            TRUE (),
            _val < 0, -1, 
            _val = 0, 0,
            _val > 0, 1
        )
    )

 

It works great :).

Helpful resources

Announcements
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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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