Forum Discussion

kav_cris's avatar
kav_cris
Frequent Visitor
3 years ago

Date difference between 2 previous months

Hi all,

 

I am trying to calculate the storage time (in days) for unsold items, historically.

Let's say I bought product A in Jan 2022 and it is still stored today.

 

DATEDIFF(Sales[PurchaseDate], TODAY(), DAY),) gives me the storage time in days up until today.

 

I want a bar chart that shows storage time in Feb 2022, March 2022, ... Feb 2023.

 

I tried replacing TODAY() with MAX(Date[Date]) or SELECTEDVALUE(Date[Date]) with no success. 

P.S. Sales table only has PurchaseDate adn SoldDate as date columns.

2 Replies

  • kav_cris's avatar
    kav_cris
    Frequent Visitor

    Some more info, my measure looks like this:

    Datediff =
    
    CALCULATE(
    if(
        SELECTEDVALUE('Date'[MonthEndDate]) >= SELECTEDVALUE(Sales[PurchasedDate]) ,
        DATEDIFF(SELECTEDVALUE(Sales[PurchasedDate]), SELECTEDVALUE('Date'[MonthEndDate]) , DAY),
        "f"
    ), USERELATIONSHIP(Sales[PurchasedDate], 'Date'[Date]))

     


    And I get this result:


    It only calculates the datediff to the month itself. 
    I want the difference to all following month ends.