Forum Discussion

varshajain's avatar
varshajain
Microsoft Employee
4 years ago
Solved

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

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!

 
  • Anonymous's avatar
    Anonymous
    4 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

5 Replies

  • Anonymous's avatar
    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:

    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

    • varshajain's avatar
      varshajain
      Microsoft Employee

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

       

  • daXtreme's avatar
    daXtreme
    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.

    • varshajain's avatar
      varshajain
      Microsoft 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.
  • Anonymous's avatar
    Anonymous
    Not applicable

    have you found the solution, I have the same problem