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
Cello_C
Frequent Visitor

Difference of dates in the date selection filter

Hi, there is a way to retrieve the filter dates given in POWER BI

Cello_C_0-1632312187363.png

I have to make the difference between the dates selected in the filter (those indicated by the red arrows) which obviously change according to the choice of those who use the report

 

Thanks

Marcello

1 ACCEPTED SOLUTION

Hello again 

 

onurbmiguel__0-1632403730365.png

Total Days = 
var min_ = min('Calendar'[Date])
var max_ = max('Calendar'[Date])
var days = DATEDIFF(min_,max_,DAY)
return 
days 

onurbmiguel__1-1632403777753.png

 

 

please analyse

 

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Best Regards
BC

 

 


Best regards


Bruno Costa | Super User


 


Did I help you to answer your question? Accepted my post as a solution! Appreciate your Kudos!! 


Take a look at the blog: PBI Portugal 


 


View solution in original post

15 REPLIES 15
onurbmiguel_
Super User
Super User

Hello, 

My sugestion is to creat a measure: 

Date_Dif = 
var Min_ = min(date) //same field of slicer
var Max_ = max(date) //same field of slicer
var total_days = DATEDIFF(Min_ , Max_ , DAY)  //https://docs.microsoft.com/pt-pt/dax/datediff-function-dax

return 

total_days

Any question ask.

 

Best regards

BC

 


Best regards


Bruno Costa | Super User


 


Did I help you to answer your question? Accepted my post as a solution! Appreciate your Kudos!! 


Take a look at the blog: PBI Portugal 


 


Ok, but I don't understand what I have to refer to date in this expression: var Min_ = min (date)
How do I refer to the filter date? Forgive me, maybe I'm missing something.

Thanks for the reply

 

Marcello

hello,  

 

date is the same field that you use in the slicer. 

 

any question ask

 

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Best Regards
BC

 


Best regards


Bruno Costa | Super User


 


Did I help you to answer your question? Accepted my post as a solution! Appreciate your Kudos!! 


Take a look at the blog: PBI Portugal 


 


Considering this example:

Cello_C_0-1632315223049.png

 

the cells in yellow are the ones where the date filter takes effect.
If I consider MIN ([Date]), the result is 07/03/2021, similarly, MAX ([Date]) the result is 25/07/2021.
What I need is the difference between 31/07/2021 and 01/03/2021: the difference between the dates indicated in the filter.
Forgive me ... maybe I'm wrong to explain

Thanks

 

Marcello

I try to explain myself better: the filter clearly refers to a field in a table.
Putting MIN([DataFilter]) returns the minimum Date value of that field ... not 01/03/2021 because, perhaps, there are no records of that date but subsequent

Hello again

My analysis : onurbmiguel__0-1632321097530.png

 

Any questions

 

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Best Regards
BC 

 

 


Best regards


Bruno Costa | Super User


 


Did I help you to answer your question? Accepted my post as a solution! Appreciate your Kudos!! 


Take a look at the blog: PBI Portugal 


 


Thanks for the answers and for the time you have dedicated me but I need the difference between 03/31/2021 and 01/01/2021 (the dates indicated in the "date filter" object regardless of the data in the table).

 

Marcello

Sorry, but I misinterpreted your question.

 

is this the correct scenario:

onurbmiguel__0-1632330993086.png

 

you need a calendar table to count the days and you must put in the slicer the date from the calendar table and not the date of the fact table

Any questions

 

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Best Regards
BC

 

 

 


Best regards


Bruno Costa | Super User


 


Did I help you to answer your question? Accepted my post as a solution! Appreciate your Kudos!! 


Take a look at the blog: PBI Portugal 


 


I'm sorry but it doesn't work: it calculates the difference between all the days of the calendar table and not on the filter selection.
Thanks anyway

hello

onurbmiguel__0-1632383311855.png

 

by the previous example what would be the intended result?

 

Best Regards 

BC

 


Best regards


Bruno Costa | Super User


 


Did I help you to answer your question? Accepted my post as a solution! Appreciate your Kudos!! 


Take a look at the blog: PBI Portugal 


 


Hi Miguel,

 

Applying this filter:

Cello_C_0-1632383846236.png

only the records highlighted in yellow are considered in this table

Cello_C_1-1632383932017.png

the filter is associated with the Date field of the table above.
In the report structure there is also a TDate table where there are all the dates of the report (CALENDARAUTO ()) which is in JOIN with the Date field of the above table.
What I need is the difference between the filter dates, so in the example 7/31/2021 - 3/1/2021.

I hope I have explained myself better.

Thanks

 

Marcello

 

So for this example the result is 152 days

 

Best Regards 

BC

 


Best regards


Bruno Costa | Super User


 


Did I help you to answer your question? Accepted my post as a solution! Appreciate your Kudos!! 


Take a look at the blog: PBI Portugal 


 


Exactly

 

Thank you

Marcello

Hello again 

 

onurbmiguel__0-1632403730365.png

Total Days = 
var min_ = min('Calendar'[Date])
var max_ = max('Calendar'[Date])
var days = DATEDIFF(min_,max_,DAY)
return 
days 

onurbmiguel__1-1632403777753.png

 

 

please analyse

 

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Best Regards
BC

 

 


Best regards


Bruno Costa | Super User


 


Did I help you to answer your question? Accepted my post as a solution! Appreciate your Kudos!! 


Take a look at the blog: PBI Portugal 


 


It works
Thanks Thanks thanks

 

Marcello

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.