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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors