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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
amiller5
Helper II
Helper II

Calculating the difference in days between two dates

I have a start date calculated as a measure and I am wanting to subtract it from "Today()" date. See image below, the first line item has a start date of 4/21/2022 and the Age (days) is 4,734 [Today's date is 6/1/2022). Not sure why it is so off?

Age (days) is a calculated column

amiller5_0-1654102247946.png

 

2 ACCEPTED SOLUTIONS
Syk
Super User
Super User

Use datediff instead

DATEDIFF('table'[start date], today(), days) 

View solution in original post

Syk
Super User
Super User

There's a start of month function you might be able to use!
STARTOFMONTH function (DAX) - DAX | Microsoft Docs

View solution in original post

6 REPLIES 6
Syk
Super User
Super User

There's a start of month function you might be able to use!
STARTOFMONTH function (DAX) - DAX | Microsoft Docs

Ok - so I created this Date Key

amiller5_0-1656630164565.png

And I have the following formula: 

Age (Days) = DATEDIFF('Service 4 - Contract accts'[Start date],STARTOFMONTH('Date key'[Date]),DAY)
 
but now my days in the able for the example is (-)
amiller5_1-1656630399624.png

 

 

I was able to get the correct days to flow through by ONLY putting the month I am referencing in the Date key. Is there anyway to put all months in the key and point to the current month? to eliminate having to refresh that date every time?

 

abusen333
Frequent Visitor

you can do eather ways;
1- Using Date Diff Dax Function 
Age in days Measure =
DATEDIFF (
    MIN ( Mytable[Start Date] ),
    TODAY (),
    DAY
)
2- Normal Substraction
INT(

       MIN ( Mytable[Start Date] ) - Today()

)
 
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Syk
Super User
Super User

Use datediff instead

DATEDIFF('table'[start date], today(), days) 

Is there a calculation for an "as of" date? Similar to the equation you supplied above, instead of TODAY(), is there something to make it calculate off of as of first of current month?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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