Forum Discussion

Nico_Beckers's avatar
Nico_Beckers
Frequent Visitor
4 years ago
Solved

Difference between current and previous cell, reset every new day

Hello, 

 

I have this kind of data set:

DateTimeAccumulative countAmount per hour
01/05/202201:0011
01/05/202202:0021
01/05/202203:0075
01/05/202204:0092
01/05/202205:00156
02/05/202201:0033
02/05/202202:0096
02/05/202203:00123
02/05/202204:002513
02/05/202205:00283
03/05/202201:0000
03/05/202202:001515
03/05/202203:00183
03/05/202204:00191
03/05/202205:00234

 

So basicly I have an accumulative count, that gets reset every day at a certain time. What I want to know is the amount per hour, but reset every day. I tried with a merged double index, one starting at 0, the other at 1, but then I dont take the dates into account.

 

Anyone has an idea how to fix this in power query?

 

Many thanks!

Nico

  • Nico_Beckers , Try a new column like

     

    New column =
    var _date = datevalue([Date Time])
    var _max = maxx(filter(Table, [Date Time] < earlier([Date Time]) && datevalue([Date Time]) = _date), [Date Time] )
    return
    [Accumulative] - maxx(filter(Table, [Date Time] =_max && datevalue([Date Time]) = _date), [Accumulative] )

4 Replies

  • Nico_Beckers , Try a new column like

     

    New column =
    var _date = datevalue([Date Time])
    var _max = maxx(filter(Table, [Date Time] < earlier([Date Time]) && datevalue([Date Time]) = _date), [Date Time] )
    return
    [Accumulative] - maxx(filter(Table, [Date Time] =_max && datevalue([Date Time]) = _date), [Accumulative] )

  • Nathaniel_C's avatar
    Nathaniel_C
    Icon for Community Champion rankCommunity Champion

    Hi Nico_Beckers ,
    Please try this:

    Dax Accumulative Count =
    VAR _date =
        MAX ( dif[Date] )
    VAR _Time =
        MAX ( dif[Time] )
    VAR _amountPerHour =
        MAX ( dif[Amount per hour] )
    VAR _calc =
        CALCULATE (
            SUM ( dif[Amount per hour] ),
            FILTER ( ALL ( dif ), dif[Date] = _date && dif[Time] <= _Time )
        )
    RETURN
        _calc
    


    Let me know if you have any questions.

    If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
    Nathaniel

     

    • Nico_Beckers's avatar
      Nico_Beckers
      Frequent Visitor

      Hi Nathaniel, 

       

      This gives me the accumulative count no? I want to calculate the amount per hour starting from the accumulative count. Or did I miss something?

      • Nathaniel_C's avatar
        Nathaniel_C
        Icon for Community Champion rankCommunity Champion

        Hi Nico_Beckers ,
        Sorry for misunderstanding. Still not sure what you want. Perhaps you could provide a picture of your expected outcome. 

        Let me know if you have any questions.

        If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
        Nathaniel