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
jackcoxer
Frequent Visitor

IF most recent month then one metric, if not another

This is driving me mad. I want to be able to use a seperate metric for the most recent month. I've got the below calculation and it's working for the most recent period but not for the previous one.

Measure = 
VAR MaxMonth = CALCULATE(MAX('Calendar'[FISCAL_PERIOD]), 'OPS_BONUS MANUAL_TECHNICIAN_IO_VW'[BONUS_PAYMENT] > 0)
VAR BonusCurrent = sum('OPS_BONUS MANUAL_TECHNICIAN_IO_VW'[BONUS_PAYMENT])
VAR BonusPrevious = SUM('OPS_BONUS MANUAL_TECHNICIAN_VIEW_TECH_OPTI_WEEKLY_SNAPSHOT_VW'[Column])
RETURN
IF(VALUES('Calendar'[FISCAL_PERIOD]) = MaxMonth, BonusCurrent, BonusPrevious)
However it's just showing the BonusCurrent for all values on the bar chart.
1 REPLY 1
DataInsights
Super User
Super User

@jackcoxer,

 

Try this measure:

 

Bonus Measure =
VAR MaxMonth =
    CALCULATE (
        MAX ( 'Calendar'[FISCAL_PERIOD] ),
        ALL ( 'Calendar' ),
        'OPS_BONUS MANUAL_TECHNICIAN_IO_VW'[BONUS_PAYMENT] > 0,
        CROSSFILTER ( 'Calendar'[Date], 'OPS_BONUS MANUAL_TECHNICIAN_IO_VW'[Date], BOTH )
    )
VAR BonusCurrent =
    SUM ( 'OPS_BONUS MANUAL_TECHNICIAN_IO_VW'[BONUS_PAYMENT] )
VAR BonusPrevious =
    SUM ( 'OPS_BONUS MANUAL_TECHNICIAN_VIEW_TECH_OPTI_WEEKLY_SNAPSHOT_VW'[Column] )
RETURN
    IF ( MAX ( 'Calendar'[FISCAL_PERIOD] ) = MaxMonth, BonusCurrent, BonusPrevious )

 

I'm assuming that you have a "1:*" unidirectional relationship between Calendar and each fact table using the Date column. The CROSSFILTER function allows you to filter from the fact table to the Calendar table. The ALL function clears the Calendar filter context in the visual. Also, in the final line I changed VALUES to MAX. VALUES returns a table, and you can't compare a table to a scalar.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.