Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

DAX Variable + Selected Value with Date and Time

Hi together,

I got an issue with this Dax-Formula. The part with the variable and SelectedValue is not working. I am selecting the value in a visual table. The format of the Selected Value is dd/mm/yyyy hh:mm:ss.

Can anybody help me with this issue?




InDateTimeRange =

 

var _rangeStart= SELECTEDVALUE(Data[TimestampFrom])

 

var _rangeEnd= SELECTEDVALUE(Data[TimestampTo])

 

return

 

IF(

 

SELECTEDVALUE(Data[TimestampFrom]) >= _rangeStart

 

&& SELECTEDVALUE(Data[TimestampTo]) <= _rangeEnd

 

&& SELECTEDVALUE(Data[TimestampTo]) <>BLANK()

 

, 1, 0)

 

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Anonymous ,

     

    If you want to set a dynamic flag for rows based on the date period selected in slicer, I'd suggest you firstly add a new Date table:

    Date Slicer = CALENDAR(MIN('Data'[TimestampFrom]),MAX('Data'[TimestampTo])+1 ) 

    Then modify your measure like:

    InDateTimeRange = 
    var _rangeStart= MIN('Date Slicer'[Date])
    var _rangeEnd= MAX('Date Slicer'[Date])
    return
    IF(MAX(Data[TimestampFrom]) >= _rangeStart&& MAX(Data[TimestampTo]) <= _rangeEnd&& MAX(Data[TimestampTo]) <>BLANK(), 1, 0)

    Output:

     

    Best Regards,
    Eyelyn Qin
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    If you want to set a dynamic flag for rows based on the date period selected in slicer, I'd suggest you firstly add a new Date table:

    Date Slicer = CALENDAR(MIN('Data'[TimestampFrom]),MAX('Data'[TimestampTo])+1 ) 

    Then modify your measure like:

    InDateTimeRange = 
    var _rangeStart= MIN('Date Slicer'[Date])
    var _rangeEnd= MAX('Date Slicer'[Date])
    return
    IF(MAX(Data[TimestampFrom]) >= _rangeStart&& MAX(Data[TimestampTo]) <= _rangeEnd&& MAX(Data[TimestampTo]) <>BLANK(), 1, 0)

    Output:

     

    Best Regards,
    Eyelyn Qin
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • themistoklis's avatar
    themistoklis
    Community Champion

    Anonymous 

    Can you try removing the selectedvalue from the if statement and then check if it works ok?

     

    InDateTimeRange =

     

    var _rangeStartSELECTEDVALUE(Data[TimestampFrom])

     

    var _rangeEndSELECTEDVALUE(Data[TimestampTo])

     

    return

     

    IF(

    Data[TimestampFrom] >= _rangeStart

    && Data[TimestampTo] <= _rangeEnd

    && Data[TimestampTo] <>BLANK()

    10)

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi, this is unfortunately not working. The Dax Formula can not find the column in the Data, because it is not aggregated. 

      • tatees's avatar
        tatees
        Frequent Visitor

        Hi Did you find solution for the above issue? I am facing same problem.