Forum Discussion
varshajain
4 years agoMicrosoft 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('Candida...
- Anonymous4 years ago
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:
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
daXtreme
4 years agoSolution 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.
varshajain
4 years agoMicrosoft Employee
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.