Forum Discussion

amiller5's avatar
amiller5
Helper II
4 years ago
Solved

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

 

6 Replies

  • Syk's avatar
    Syk
    Resident Rockstar

    Use datediff instead

    DATEDIFF('table'[start date], today(), days) 
    • amiller5's avatar
      amiller5
      Helper II

      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?

  • abusen333's avatar
    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.
    • amiller5's avatar
      amiller5
      Helper II

      Ok - so I created this Date Key

      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's avatar
        amiller5
        Helper II

        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?