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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Super User
Super User

hi @kav_cris 

try to provide sample dataset with expected result.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.