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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
varshajain
Microsoft Employee
Microsoft 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
Anonymous
Not applicable

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
Anonymous
Not applicable

have you found the solution, I have the same problem

Anonymous
Not applicable

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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