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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
JAB
Advocate II
Advocate II

Cannot use Date column in IF DAX query

I have a rolling 12 month calculation which should only show a value from 20201130 and onwards, so the december value for 2020 will be based on the calculation going 12 month back. The reason is that in november 2020 there is not data for going 12 month back.

 

The formual is like this:

 

PPM Produced R12 M:=
var _pp=
CALCULATE (
[PPM Produced],

DATESINPERIOD (
'Calendar'[CalendarDate],
MAX ( 'Calendar'[CalendarDate] ),
-1,
YEAR
)
)

return
if('Calendar'[CalendarDate]>20201130,_pp,0)

 

Any ideas on how I can solve the issue

1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hi @JAB ,

 

If you need a calculated column,using below dax expression:

_PPM Produced R12 M = 
var _pp= CALCULATE([Measure],DATESINPERIOD('Table'[Date],'Table'[Date],-1,YEAR))
Return
IF('Table'[Date]>DATE(2020,11,30),_pp,0)

If a measure is needed,then try:

PPM Produced R12 M = 
var _pp= CALCULATE([Measure],DATESINPERIOD('Calendar'[Date],MAX('Calendar'[Date]),-1,YEAR))
Return
IF(MAX('Calendar'[Date])>DATE(2020,11,30),_pp,0)

And you will see:

v-kelly-msft_0-1615268247753.png

 

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

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

View solution in original post

4 REPLIES 4
v-kelly-msft
Community Support
Community Support

Hi @JAB ,

 

If you need a calculated column,using below dax expression:

_PPM Produced R12 M = 
var _pp= CALCULATE([Measure],DATESINPERIOD('Table'[Date],'Table'[Date],-1,YEAR))
Return
IF('Table'[Date]>DATE(2020,11,30),_pp,0)

If a measure is needed,then try:

PPM Produced R12 M = 
var _pp= CALCULATE([Measure],DATESINPERIOD('Calendar'[Date],MAX('Calendar'[Date]),-1,YEAR))
Return
IF(MAX('Calendar'[Date])>DATE(2020,11,30),_pp,0)

And you will see:

v-kelly-msft_0-1615268247753.png

 

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

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

It worked, thank you very much 🙂

PC2790
Community Champion
Community Champion

Can you try using this formula instead of your DATESINPERIOD calculation:

CALCULATE([PPM Produced],DATESBETWEEN(DatesTable[Date],MAX(Calendar[Calendardate])-365,MAX(Calendar[Calendardate]))) 

Thank you for your input. I am not certain how it shold be used, the calculation of the variable works fine, it removing those values/calculations older than 20201130 that is the issue.

I did try your suggestion but without luck.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.