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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
nikhil893
New Member

How to dynamically calculate the difference between two dates selected from a slicer?

 

We want to calculate the difference in seconds  between the two dates( start and end) selected from a slicer. As we are very new to this could anyone please help us out?

 

Thank you,

Nikhil Pranav

1 ACCEPTED SOLUTION

Hi @nikhil893,

 

PorkChop's DAX expression works fine.

Measure = DATEDIFF(MIN(Sales[Date]),MAX(Sales[Date]),DAY)&" Days"
Capture.PNGUntitled.png

 

Regards,

Charlie Liao

View solution in original post

7 REPLIES 7
PorkChop
Advocate I
Advocate I

Hey dude.

 

If you are doing this in dax it's super simple.

 

 

=DATEDIFF([Startdate],[EndDate],second)
The Mystic Statistic

@PorkChop : We need to have the start and end dates to be selected from the user using a slicer. Will this measure work for that too ? We do not have any columns named ' Start date' and 'end date'. We have only one column as date which we are using in a slicer.Capture.PNG

Hi @nikhil893,

 

PorkChop's DAX expression works fine.

Measure = DATEDIFF(MIN(Sales[Date]),MAX(Sales[Date]),DAY)&" Days"
Capture.PNGUntitled.png

 

Regards,

Charlie Liao

*flexes*

The Mystic Statistic

Interesting, maybe you could try

 

=DATEDIFF(min([DATE]),max([DATE]),second)

where [DATE] is the columnname of the slicer you are using?

The Mystic Statistic

@PorkChop : The DATE coulmn may have dates from 1 Nov 2016 till 30 Nov 2016. The selection from the slicer could be 2 Nov (start date) and 4 Nov (End date). We need these two dates ( 2 Nov and 4 Nov) , not the min and max dates in the date column. Will this measure work for that ?

Well i've not tested it i practice but it should do. When you are filtering using the slicer, it's actually like creating a new table of entries between those two dates. If we then pick the smallest and largest values in that table it's the same effect.

 

You'll want to test it, as I haven't but syntactically should be correct.

The Mystic Statistic

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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