Forum Discussion

Kohrinn's avatar
Kohrinn
Icon for Helper I rankHelper I
2 years ago
Solved

Average time between events

Hi all,

 

I have a table CIP_CIPStationConcentrates and I want to calculate the average time inbetween the replenishments (ActionID=11) for caustic tank (TankID = 1) from CIP Station 1 (there is only CIP Station 1 in my example, but in general there can be many). How to calculate it? I would expect the answer to be 11 days - since it's 2 days between first and second replenishment and 20 days between second and third.

 

Thank you!

Joanna

 

 

ActionIDActionNameActionDateTankIDTankNameAmountCIP Station
12Consumption2023.10.11 09:122CIP Acid tank4,01
11Replenishment2023.10.11 12:031CIP Caustic tank500,01
11Replenishment2023.10.11 12:042CIP Acid tank500,01
11Replenishment2023.10.11 12:075CIP Disinfectant500,01
12Consumption2023.10.11 12:121CIP Caustic tank5,31
12Consumption2023.10.11 12:125CIP Disinfectant4,51
12Consumption2023.10.11 13:121CIP Caustic tank5,31
12Consumption2023.10.11 14:201CIP Caustic tank4,71
12Consumption2023.10.11 16:121CIP Caustic tank5,61
12Consumption2023.10.11 19:201CIP Caustic tank6,11
12Consumption2023.10.11 21:121CIP Caustic tank4,31
12Consumption2023.10.11 22:201CIP Caustic tank2,71
12Consumption2023.10.12 00:121CIP Caustic tank3,71
12Consumption2023.10.12 05:121CIP Caustic tank2,81
12Consumption2023.10.12 07:121CIP Caustic tank2,11
12Consumption2023.10.12 09:132CIP Acid tank5,01
12Consumption2023.10.12 12:121CIP Caustic tank3,31
12Consumption2023.10.12 13:135CIP Disinfectant5,51
12Consumption2023.10.12 15:121CIP Caustic tank5,11
12Consumption2023.10.12 19:121CIP Caustic tank5,01
12Consumption2023.10.12 21:121CIP Caustic tank5,41
12Consumption2023.10.13 00:121CIP Caustic tank4,31
12Consumption2023.10.13 03:121CIP Caustic tank3,91
12Consumption2023.10.13 06:121CIP Caustic tank4,31
12Consumption2023.10.13 09:121CIP Caustic tank6,11
12Consumption2023.10.13 09:142CIP Acid tank6,01
11Replenishment2023.10.13 12:031CIP Caustic tank499,01
12Consumption2023.10.13 14:145CIP Disinfectant6,51
12Consumption2023.11.01 09:121CIP Caustic tank4,01
11Replenishment2023.11.02 12:031CIP Caustic tank500,01
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Kohrinn 

     

    You can create several calculated columns as follow.

    Datediff = 
    VAR _lastdate =
        CALCULATE (
            MAX ( CIP_CIPStationConcentrates[ActionDate] ),
            FILTER (
                CIP_CIPStationConcentrates,
                [ActionID] = EARLIER ( CIP_CIPStationConcentrates[ActionID] )
                    && [TankID] = EARLIER ( CIP_CIPStationConcentrates[TankID] )
                    && [CIP Station] = EARLIER ( CIP_CIPStationConcentrates[CIP Station] )
                    && [ActionDate] < EARLIER ( CIP_CIPStationConcentrates[ActionDate] )
            )
        )
    RETURN
        DATEDIFF ( _lastdate, [ActionDate], DAY )

     

    Time = 
    AVERAGEX (
        FILTER (
            CIP_CIPStationConcentrates,
            [ActionID] = EARLIER ( CIP_CIPStationConcentrates[ActionID] )
                && [TankID] = EARLIER ( CIP_CIPStationConcentrates[TankID] )
                && [CIP Station] = EARLIER ( CIP_CIPStationConcentrates[CIP Station] )
        ),
        [Datediff]
    )

     

    Is this the result you expect?

     

    Best Regards,
    Community Support Team _Yuliax

     

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

4 Replies

  • Kohrinn , Create a new column

     

    New Column=
    Var _max = maxx(filter(Table, Table[ActionID] = earlier(Table[ActionID]) && [TankID] <earlier([TankID])), [TankID])
    return
    if(isblank(_max), blank(),
    datediff( maxx(filter(Table, Table[ActionID] = earlier(Table[ActionID]) && [TankID] =_max),[ActionDate]) , [ActionDate], day) )

     

     

    You can use Avg in measure

    • Kohrinn's avatar
      Kohrinn
      Icon for Helper I rankHelper I

      Something's not right.

       

       

      There should be "2" in the secon row.

       

       

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Kohrinn 

     

    You can create several calculated columns as follow.

    Datediff = 
    VAR _lastdate =
        CALCULATE (
            MAX ( CIP_CIPStationConcentrates[ActionDate] ),
            FILTER (
                CIP_CIPStationConcentrates,
                [ActionID] = EARLIER ( CIP_CIPStationConcentrates[ActionID] )
                    && [TankID] = EARLIER ( CIP_CIPStationConcentrates[TankID] )
                    && [CIP Station] = EARLIER ( CIP_CIPStationConcentrates[CIP Station] )
                    && [ActionDate] < EARLIER ( CIP_CIPStationConcentrates[ActionDate] )
            )
        )
    RETURN
        DATEDIFF ( _lastdate, [ActionDate], DAY )

     

    Time = 
    AVERAGEX (
        FILTER (
            CIP_CIPStationConcentrates,
            [ActionID] = EARLIER ( CIP_CIPStationConcentrates[ActionID] )
                && [TankID] = EARLIER ( CIP_CIPStationConcentrates[TankID] )
                && [CIP Station] = EARLIER ( CIP_CIPStationConcentrates[CIP Station] )
        ),
        [Datediff]
    )

     

    Is this the result you expect?

     

    Best Regards,
    Community Support Team _Yuliax

     

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