Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

DAX with Today (text data type), Last 7 dates(with text data type) and future dates(date data type)?

Hi Team,

I am new to power bi.

Kindly please help me below dax issue with date dropdown filter.

Like, Today date with Text Data Type

         Last 7 days with Text Data Type

          and Future dates with Date Data Type.

Kindly please he me on this case. I need to go all above cases in one dropdown filter. please help me best approch? 

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi  Anonymous ,

    I created some data:

    Are you referring to the selection of the slicer to display the corresponding date.

    Table1:

    Table2:

     

    Here are the steps you can follow:

    1. Create measure.

    Flag =
    var _select=SELECTEDVALUE('Table'[Slicer])
    var _today=TODAY()
    return
    SWITCH(
        TRUE(),
        _select="Today"&&MAX('Table 2'[Date])=_today,1,
        _select="Last 7 dates"&&MAX('Table 2'[Date])>=_today-7&&MAX('Table 2'[Date])<_today,1,
        _select="future dates"&&MAX('Table 2'[Date])>_today,1,0)

     2. Place [Flag]in Filters, set is=1, apply filter.

    3. Result:

     

     

    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

3 Replies

  • Ashok507's avatar
    Ashok507
    Frequent Visitor

    I think it can be achieved using

    "detect data type" option in" transform" tab of "power query editor"me.

    • Anonymous's avatar
      Anonymous
      Not applicable

      No it is not working we will go with dax commands.
      please suggest with DAX command!

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  Anonymous ,

    I created some data:

    Are you referring to the selection of the slicer to display the corresponding date.

    Table1:

    Table2:

     

    Here are the steps you can follow:

    1. Create measure.

    Flag =
    var _select=SELECTEDVALUE('Table'[Slicer])
    var _today=TODAY()
    return
    SWITCH(
        TRUE(),
        _select="Today"&&MAX('Table 2'[Date])=_today,1,
        _select="Last 7 dates"&&MAX('Table 2'[Date])>=_today-7&&MAX('Table 2'[Date])<_today,1,
        _select="future dates"&&MAX('Table 2'[Date])>_today,1,0)

     2. Place [Flag]in Filters, set is=1, apply filter.

    3. Result:

     

     

    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