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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Hchazelle
New Member

Create a MTH measure from a YTD column

Dear all,

 

I have a table with a column YTD Actuals VS LY with a YTD value for each month.

I am trying to calculate a MTH Actuals VS LY from this YTD data.

 

To do this, I am planning to first make a measure to calculate the previous month YTD Actuals VS LY and then substract it to the YTD Actuals VS LY

 

To calculate the previous month YTD Actuals VS LY, here is the measure I made:

=CALCULATE([ACT_VS_LY@CR];PREVIOUSMONTH('Calendar'[date]))

Hchazelle_0-1615987625491.png

As you can see in TEST measure, it is working, except that for the month of January 2021 (202101) I have the 364 from December while for January i should always have 0.

I created a date table linked to my data table.

Could you please help me find a way so that if the year of previous month is not the same as the year of my filter context, then the measure returns 0 ?

 

Thanks for your help !

Henri

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Hchazelle , Try a measure like

 

measure =
var _1 = CALCULATE([ACT_VS_LY@CR];datesMTD('Calendar'[date]))
var _2 = CALCULATE([ACT_VS_LY@CR];PREVIOUSMONTH('Calendar'[date]))
return
Switch( True() ,
not(isblank(_1) ) && not(isblank(_2) ) , _1 - _2 ,
isblank(_1) , 0,
isblank(_2),_1
)

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Hchazelle , Try a measure like

 

measure =
var _1 = CALCULATE([ACT_VS_LY@CR];datesMTD('Calendar'[date]))
var _2 = CALCULATE([ACT_VS_LY@CR];PREVIOUSMONTH('Calendar'[date]))
return
Switch( True() ,
not(isblank(_1) ) && not(isblank(_2) ) , _1 - _2 ,
isblank(_1) , 0,
isblank(_2),_1
)

Thanks a lot, that's perfect !

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.