Forum Discussion

nehajadhav166's avatar
nehajadhav166
Resolver I
4 years ago
Solved

Get selected value from date slicer

Hi Experts,

 

I have date slicer like this

When I select value from slicer I want to capture that date range. I want to use this date range as part of other measure filter.

For example I want date range 1/10/2022 to 6/12/2022 and not min and max dates.

I tried selected value function but it did not work.

Any pointers here?

 

Thanks in advance.

 

Regards,

Neha

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi nehajadhav166 ,

    Since you did not give a specific table, I had to create my own table for testing according to your description, please point out if there are any problems.

    Please try below steps:

    1. below is my test table

    Table:

    Date Table(create from "Table" with dax):

     

    Date Table = CALENDAR(FIRSTDATE('Table'[Date]),LASTDATE('Table'[Date]))

     

    Model:

    2. add a slicer with "Date Table[Date]",create a measure and add it to card visual

     

    Sum for Sales =
    VAR maxdate =
        MAXX ( ALLSELECTED ( 'Date Table'[Date] ), [Date] )
    VAR mindate =
        MINX ( ALLSELECTED ( 'Date Table' ), [Date] )
    VAR tmp =
        CALENDAR ( mindate, maxdate )
    RETURN
        CALCULATE ( SUM ( 'Table'[Sales] ), tmp )
    

     

    Please refer the attached .pbix file.

    ā€ƒ

    Best regards,
    Community Support Team_ Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 Replies

  • nehajadhav166 ,

     

    Measure =

    var _tab = values(date[Date])

    return

    countrows(filter(Table, Table[Date] in _tab) )

     

    Or between

     

    new measure =
    var _max = maxx(allselected(Date),Date[Date])
    var _min = minx(allselected(Date),Date[Date])
    return
    calculate( sum(Table[Value]), filter('Table', 'Table'[Date] >=_min && 'Table'[Date] <=_max))

     

  • Hi Amit,

    Thanks for quick reply.

    I do not understand how countrows will help to get values selected from date slicer?

    Can you please elaborate?

     

    Thanks,

    Neha

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi nehajadhav166 ,

    Since you did not give a specific table, I had to create my own table for testing according to your description, please point out if there are any problems.

    Please try below steps:

    1. below is my test table

    Table:

    Date Table(create from "Table" with dax):

     

    Date Table = CALENDAR(FIRSTDATE('Table'[Date]),LASTDATE('Table'[Date]))

     

    Model:

    2. add a slicer with "Date Table[Date]",create a measure and add it to card visual

     

    Sum for Sales =
    VAR maxdate =
        MAXX ( ALLSELECTED ( 'Date Table'[Date] ), [Date] )
    VAR mindate =
        MINX ( ALLSELECTED ( 'Date Table' ), [Date] )
    VAR tmp =
        CALENDAR ( mindate, maxdate )
    RETURN
        CALCULATE ( SUM ( 'Table'[Sales] ), tmp )
    

     

    Please refer the attached .pbix file.

    ā€ƒ

    Best regards,
    Community Support Team_ Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • nehajadhav166's avatar
      nehajadhav166
      Resolver I

      Anonymous ,

      Thank you for reply.

      I tried this approch and it worked for me.

      Var selected_maxdate=IF.EAGER( (ISFILTERED ( 'TestData'[Date] )),MAX ( 'TestData'[Date] ),MAX(TestData[Date]))
      Var selected_mindate=IF.EAGER( (ISFILTERED ( 'TestData'[Date] )),MIN ( 'TestData'[Date] ),MIN(TestData[Date]))
       
      Allselected and min/max did not wor for me.
      Thanks,
      Neha