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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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