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
alexggrantham
Frequent Visitor

Help with DATEADD

Hello,

 

I have a date table joined to a fact table and I'm counting rows in the fact table.

The ultimate goal is to be able to count the rows in the fact table where the date is before the Max Date, which is the most recent date for which there is data (19/11/2024). I also want to be able to do the same for last year i.e. count rows where the date is prior to 19/11/2023.

alexggrantham_0-1732098352300.png

To do this I need to calculate the most recent date for which there is data and I have achieved this with the following code:

alexggrantham_1-1732098501904.png

However, as you can see, the Max Date with DATEADD is not returning 19/11/2023 as I wanted it to. It is returning the max date per month.

alexggrantham_2-1732098714488.png

How can the Max Date measure be written in such a way that when used in a DATEADD function, it returns the same date a year ago, for all rows?

 

Thank you.

1 ACCEPTED SOLUTION
Rupak_bi
Solution Sage
Solution Sage

Try This

Max date dateadd = calculate([Max Date],dateadd(date[Max Date],-1,Year))
alternate
Max date dateadd =

var _day = day([Max Date])
Var _month = Month([Max Date])
Var _Year_P = Year([Max Date])-1
Return
date(_year_P,_month,_day)

 

 



Regards
Rupak
FOLLOW ME : https://www.linkedin.com/in/rupaksar/

View solution in original post

1 REPLY 1
Rupak_bi
Solution Sage
Solution Sage

Try This

Max date dateadd = calculate([Max Date],dateadd(date[Max Date],-1,Year))
alternate
Max date dateadd =

var _day = day([Max Date])
Var _month = Month([Max Date])
Var _Year_P = Year([Max Date])-1
Return
date(_year_P,_month,_day)

 

 



Regards
Rupak
FOLLOW ME : https://www.linkedin.com/in/rupaksar/

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.