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
varshajain
Employee
Employee

Get User selected dates in date range

I have a DAX function to retrieve teh date range that user has selected

Dates = var _max = maxx(allselected('Candidates'[CreateDate]),'Candidates'[CreateDate])
var _min = minx(allselected('Candidates'[CreateDate]),'Candidates'[CreateDate])  
return _min 
User selected date is
varshajain_1-1660853644799.png

I'd like to get 6/1/2022 and 7/31/2022 in my DAX function. However, I notice that with the above DAX I am getting 6/4/2022 as the minimum as the earliest data in my table for this range is dated as 6/4/2022. 

Is there a way to get 6/1/2022 and 7/31/2022 or whatever user selects in that date filter?

 

Thanks!

 
1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @varshajain ,

Here are the steps you can follow:

1. Create measure.

mindate =
var _minx=MINX(ALLSELECTED('Table'),[Date])
var _maxx=MAXX(ALLSELECTED('Table'),[Date])
return
DATE(YEAR(_minx),MONTH(_minx),1)
mindate =
var _minx=MINX(ALLSELECTED('Table'),[Date])
var _maxx=MAXX(ALLSELECTED('Table'),[Date])
return
DATE(YEAR(_minx),MONTH(_minx),1)

2. Result:

vyangliumsft_0-1661242971691.png

If you need pbix, please click here.

Get User selected dates in date range.pbix

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

5 REPLIES 5
aycabayraktar
Frequent Visitor

have you found the solution, I have the same problem

v-yangliu-msft
Community Support
Community Support

Hi  @varshajain ,

Here are the steps you can follow:

1. Create measure.

mindate =
var _minx=MINX(ALLSELECTED('Table'),[Date])
var _maxx=MAXX(ALLSELECTED('Table'),[Date])
return
DATE(YEAR(_minx),MONTH(_minx),1)
mindate =
var _minx=MINX(ALLSELECTED('Table'),[Date])
var _maxx=MAXX(ALLSELECTED('Table'),[Date])
return
DATE(YEAR(_minx),MONTH(_minx),1)

2. Result:

vyangliumsft_0-1661242971691.png

If you need pbix, please click here.

Get User selected dates in date range.pbix

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Thank You for your response. I also did something similar to solve my issue by constructing the date based on month and year 

 

daXtreme
Solution Sage
Solution Sage

ALLSELECTED is not the right function to use in this context since there's no iteration going on in the visual. This is why it returns the whole column. It is the most complex function in whole DAX and it should be well understood before one can use it. If one doesn't, then please don't. In yur case you should put the whole table as the first argument under min/max to get what you want.

I updated my function to this

Dates = var _max = max('Candidates'[CreateDate])
var _min = min('Candidates'[CreateDate]) 
return _min 
However, I still the same issue. My expected result is to see 6/1/2022 but it shows 6/4/2022 which happens to be the earliest date for data in table. Also, the _max is returning 7/30/2022 as opposed to 7/31/2022.

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