Forum Discussion

Atis112's avatar
Atis112
New Member
3 years ago
Solved

Filter by date and time

Hello,

 

I would like to ask for help!
I would like to set up a dynamic filtering option that would pre-filter the data based on the criteria you specify.
The start date is always the previous day and 6am. The end date: is always today and 6am. So I want to see the data between the time interval. I could do this for date, but not for time.
In the table, the date and time are in two separate columns, if it is easier I can merge them.
What are the options?
Thank you very much for your help!

Best regards,
Atis

  • Hi , Atis112 

    According to your description, you want to filter the data from previous day 6am to today 6am.

    Here are the steps you can refer to :

    (1)This is my test data:

    (2)We can create a measure like this:

    Measure = var _today  = TODAY()
    var _previoud_day = TODAY()-1
    var _cur_day =  MAX('Table'[Date]) 
    var _cur_time =   MAX('Table'[Time])
    return
    IF( OR( _cur_day= _today && _cur_time<= TIME(6,0,0) ,  _cur_day= _previoud_day && _cur_time>= TIME(6,0,0) ) ,1,-1)

     

    (3)Then we can put the measure on the visual and configure it:

     

     

    If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

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

     

5 Replies

  • Hi , Atis112 

    According to your description, you want to filter the data from previous day 6am to today 6am.

    Here are the steps you can refer to :

    (1)This is my test data:

    (2)We can create a measure like this:

    Measure = var _today  = TODAY()
    var _previoud_day = TODAY()-1
    var _cur_day =  MAX('Table'[Date]) 
    var _cur_time =   MAX('Table'[Time])
    return
    IF( OR( _cur_day= _today && _cur_time<= TIME(6,0,0) ,  _cur_day= _previoud_day && _cur_time>= TIME(6,0,0) ) ,1,-1)

     

    (3)Then we can put the measure on the visual and configure it:

     

     

    If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

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

     

    • Atis112's avatar
      Atis112
      New Member

      Hello, v-yueyunzh-msft 

       

      Whoa. Yes, that's what I meant. Very perfect! Thank you very much for your help and the description of the process. It totally solved the problem!

      I have another question on the same subject:
      How can I set up slicer to list out based on start date start time and end date and end time. For example, with a slicer of four, can this be done? Do you have any ideas for this?

    • Atis112's avatar
      Atis112
      New Member

      Hello,

      FreemanZ 

      Yes, You can find it here:

      Part numberIDDateTimeQuantity
      123456789x12342023.02.035:451
      123456799x12352023.02.036:305
      123456789x12362023.02.0322:20110
      123456799x12372023.04.0423:4578
      123456789x12382023.04.043:1067
      123456799x12392023.04.0416:2250
      123456789x12402023.02.015:10765
      123456799x12412023.02.026:11864
      123456789x12422023.02.0317:15324
      123456799x12432023.02.0414:1123
      123456789x12442023.02.0518:44234
      123456799x12452023.02.0621:3456
      123456789x12462023.02.078:10876
      123456799x12472023.03.0111:4343
      123456789x12482023.02.0911:0134
      123456799x12492023.02.1018:3076

       

      Thank you very much!

      • FreemanZ's avatar
        FreemanZ
        Icon for Super User rankSuper User

        hi Atis112 

        when you say "see the data between the time interval", are you expecting to showcase that part of the table, or perform some further aggregation?