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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Anonymous
Not applicable

Previous month in if statement

Hi 🙂

 

I'm trying to create the next calculation, to show the number of alerts per month.
The calculation of the alerts differs depending on the month:

 

If the date is smaller than 2023-02-01, display a calculation based on current month data.
If the date is greater than 2023-02-01, display a calculation based on the month before last month.

 

This is the calculation:
Total alerts = SWITCH( TRUE(),
RELATED('Ref_TimeTable_Alert'[DayDate] ) < DATE ( 2023, 2, 1 ), [measure1],
[measure2])


measure2 = CALCULATE([Total payments],'BLS'[Is_Alert] = "Yes", PREVIOUSMONTH(PREVIOUSMONTH('Ref_TimeTable_Alert'[DayDate])))

 

What Total alerts gives me, is only the first part of the statemnt - data before 2023-02-01.

 

This is what I get:

YearMonthmeasure1measure2Total alerts
2022November116 116
2022December108 108
2023January8411684
2023February51108 
2023March6484 
2023April3951 

 

And this is what I would like to get:

YearMonthmeasure1measure2Total alerts
2022November116 116
2022December108 108
2023January8411684
2023February51108108
2023March648484
2023April395151

 

1 REPLY 1
Anonymous
Not applicable

Hi @Anonymous 

You can try the following measure

Total alerts =
IF (
    EOMONTH ( SELECTEDVALUE ( 'Ref_TimeTable_Alert'[DayDate] ), 0 )
        >= EOMONTH ( DATE ( 2023, 2, 1 ), 0 ),
    [measure1],
    [measure2]
)

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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