cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
kav_cris
Frequent Visitor

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 2
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:kav_cris_0-1677143692179.png


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

FreemanZ
Community Champion
Community Champion

hi @kav_cris 

try to provide sample dataset with expected result.

Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Top Solution Authors
Top Kudoed Authors