Forum Discussion

rmcmun's avatar
rmcmun
Frequent Visitor
5 years ago
Solved

Filter +/- 24 hours

Hi all,

 

I'm trying to filter a visualization so that it displays plus and minus 24 hours from the current time.

E.g., It is now 11:00 Jan 22, so my chart should display from 11:00 Jan 21 to 11:00 Jan 23?

 

How can I do this?

 

Thanks so much!

  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi rmcmun ,

     

    You could use the following formula to create a new measure :

    Measure =
    IF (
        MAX ( 'Table'[Production output time] )
            >= NOW () - 1
            && MAX ( 'Table'[Production output time] )
                <= NOW () + 1,
        1,
        0
    )

    And apply it to filter pane(set as "is 1") like this:

    Please take a look at the pbix file here.

     

    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.

7 Replies

  • PC2790's avatar
    PC2790
    Community Champion

    Hi rmcmun ,

     

    You can simply do it by fetching the current time and adding 24/24 to it, DAX of the measure would look like:

     

    Time(-24) = NOW() - 1
    Time(+24) = NOW() + 1
     
    Thanks
    • rmcmun's avatar
      rmcmun
      Frequent Visitor

      Thanks PC2790 !

      I have just posted more clarification in respose to vanessafvg . If I create those measures, how would I then use that to filter the chart? 

       

      Thanks!

      • PC2790's avatar
        PC2790
        Community Champion

        For that you cna use a 'Relative time slicer'. It will automatically get you the data of last/next 24 hours.

         

         

  • vanessafvg's avatar
    vanessafvg
    Community Champion

    can you give more details.  do you want this on the slicer, what type of visual are you using. providing the right amount of detail helps to get the right response.

     

    screen shots and sample data help too.

    • rmcmun's avatar
      rmcmun
      Frequent Visitor

      Thanks vanessafvg,

      I'm using a line chart and trying to plot expected vs. actual outputs on a production line (see screenshot).

       

      The fact table I'm plotting from (simplifying) has the following fields:

       

      - Production output time (datetime)

      - Production output volume (decimal)

      - Type (text = actual or expected)

       

      So I need to filter the chart so that it is only displaying the actual vs. expected outputs for -24 hours and +24 hours from now.

       

      Does that make sense?

       

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi rmcmun ,

     

    You could use the following formula to create a new measure :

    Measure =
    IF (
        MAX ( 'Table'[Production output time] )
            >= NOW () - 1
            && MAX ( 'Table'[Production output time] )
                <= NOW () + 1,
        1,
        0
    )

    And apply it to filter pane(set as "is 1") like this:

    Please take a look at the pbix file here.

     

    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.