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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
AndyAtDukes
New Member

Struggling with DATEDIFF

Hi, this is my first post and my first report where I am trying dynamic date/time measures and visuals, not much success so far but almost certainly down to user error.

 

I am trying to find the difference in days between two dates,

the first is a measure:

 

LastDate = CALCULATE(MAX('Calendar'[Date].[Date]),FILTER(Table1,Table1[Account Manager]<>""))

 

which appears to be working as when i put this into a card I get a date formatted correct answer.

 

DateDiff2.jpg

 

the second is a column of date values

 

DateDiff1.jpg

 

I think these are properly formatted?

 

I have then created a new column called "IsMonth" shown above far right.

 

The function in this column is:

 

IsMonth = DATEDIFF(Table1[Input Date],[LastDate],DAY)

 

But the output seems to be zero all the time, I have tried checking out solutions on the forum but can't see what I am doing wrong here.

 

Incidentally once I have this working I intend to extend the function to create a 1,0 flag in the column with something like:

 

IsMonth = IF(DATEDIFF(Table1[Input Date],[LastDate],DAY)<30,1,0)

 

where 1 indicates the Table1[Input Date] is in the last 30 days and 0 otherwise. And then to use this as a filter in visuals.

 

Thanks in anticipation

 

Andy

1 ACCEPTED SOLUTION

Matt,

 

Actually I have found another solution to this, I created a column that works out the difference in days between TODAY() and the quotation date. I can then use this to filter any metric on any number of days.

 

Thanks

 

Andy

View solution in original post

4 REPLIES 4
MattAllington
Community Champion
Community Champion

It is hard to follow your post. What are you actually  trying to do?



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Matt,

 

Actually I have found another solution to this, I created a column that works out the difference in days between TODAY() and the quotation date. I can then use this to filter any metric on any number of days.

 

Thanks

 

Andy

The problem with today() is it only works today. What if you want to see Howe many quotes they had "last 30 days" for each month this year on a chart to see a trend?  This won't work using the today approach. 

 

Take a look at this article I wrote last week to help you get your head around the recommended approach 

http://exceleratorbi.com.au/dax-time-intelligence-beginners/



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Hi Matt, thanks for your reply.

 

I have a data set of quotations created by our sales team, I am trying to build a quote performance report which will show;

 

Last 30, 90 & 180 days rolling number of quotes, value of quotes, conversion ratio etc with year/year comparison.

 

In addition I have a calendar table with sequential dates, months, years etc

 

I was trying to create the IsMonth column in order to then be able to filter by this to get that 30 days rolling data.

 

Hope that makes some sense,

 

Andy

 

 

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.