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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

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
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors