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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Calculate days between DateAdded column and Chosen Date

Good day

 

I would like to calculate as a column or as a measure, the days duration between the DateAdded column in an existing table and date chosen eg respective month end dates via a slicer.

 

The problem is that I can't calculate how many days outstanding a library book is when it has not been returned. Currently the year 3000 is being used until there is a return date.

 

Please help!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Try like

measure =
var _max = maxx(allselected('Date'), 'Date'[Date])
return
CALCUALTE(datediff(max(Table[DateAdded]),_max, day), filter(Table, year(table[DateAdded])<3000 ))

 

You have to force a row context for the correct average

to refer use values or summarize:https://community.powerbi.com/t5/Community-Blog/Decoding-Direct-Query-in-Power-BI-Part-2-Date-Difference-Across/ba-p/934397#M451

 

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , Try like

measure =
var _max = maxx(allselected('Date'), 'Date'[Date])
return
CALCUALTE(datediff(max(Table[DateAdded]),_max, day), filter(Table, year(table[DateAdded])<3000 ))

 

You have to force a row context for the correct average

to refer use values or summarize:https://community.powerbi.com/t5/Community-Blog/Decoding-Direct-Query-in-Power-BI-Part-2-Date-Difference-Across/ba-p/934397#M451

 

Anonymous
Not applicable

nikilouwgmail_0-1607418551768.png

Hi @amitchandak Amit,
thank you for the response. It worked thank you.

I need to take it a step further, if the claim has been finalised before the selected date ("fulldate" above), then I need it to calculate those days in stead of from dateadd to selected date.

Also, how would I create an additional measure whereby I calculate the average duration for say a range of products rather than specific claims?

Anonymous
Not applicable

Hi @amitchandak 

Can you help me further, please?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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