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

How to calculate Date Difference for all rows based on dynamic date

Hello guys,

In Table 1, I have 2 date columns and 1 date differnce column.  In 4th column, I wrote a simple query to classify date differnce to create groupings. (see screenshot 1). I am showing the count of each grouping on the Dashboard.

Snippet1.png

The Table 2 is 'Date Table' (see screenshot 2) and both tables are linked with Date columns.

Snippet2.png

 

> On Dashboard I also have a filter from Table 2 which will allow user to select random date from past.

> Is it possible to recalculate date difference between Date 1 (from Table 1) and Date selected by user. After this i want to show updated grouping count on dashboard.

I tried creating some measures but it is not evaluating dynamically. Can you help me with this?

 
 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

@lbendlin , Following solution worked for me:-

1. Measure on Date Table:

UserSelectedDate = CALCULATE(MAX(Dates[Date]), ALLSELECTED(Dates[Date]))
2. Measure on Table 1:
DynamicDateDiff = SUMX(Table1, DATEDIFF(Table1[Date1],[UserSelectedDate ],DAY))
I write one more measure to calculate grouping.

View solution in original post

5 REPLIES 5
v-eachen-msft
Community Support
Community Support

Hi @Anonymous ,

 

Just to supplement Ibendlin’s reply, you could use ABS() function to return positive values.

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
lbendlin
Super User
Super User

You need two measures. One for the datediff

 

datedifference = 

var sel = selectedvalue(slicerdate)

return datediff([date 1],[sel])

 

and one for the bucketing/grouping

 

grouping =

switch (true(), datedifference<11,"0-10",datedifference<21,"10-20",..."longer")

 

 

Anonymous
Not applicable

@lbendlin, Thanks for your reply.

In following measure, how can we use  date 1 column as attribute directly in formula. System does not allow to use column while creating measure. Please correct me if I am understanding it wrong.

 

datedifference = 

var sel = selectedvalue(slicerdate)

return datediff([date 1],[sel])

 

My requirement was to re-evaluate whole DateDiff and Grouping column for each row after user selects the date from slicer, so that I grouping count get directly updated on dashobard.

use max() or selectedvalue() or similar.

 

I also omitted the last parameter of datediff - you need to set that to days.

Anonymous
Not applicable

@lbendlin , Following solution worked for me:-

1. Measure on Date Table:

UserSelectedDate = CALCULATE(MAX(Dates[Date]), ALLSELECTED(Dates[Date]))
2. Measure on Table 1:
DynamicDateDiff = SUMX(Table1, DATEDIFF(Table1[Date1],[UserSelectedDate ],DAY))
I write one more measure to calculate grouping.

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.

Top Solution Authors
Top Kudoed Authors