Forum Discussion

MathieuF's avatar
MathieuF
Helper III
3 years ago

Find the previous action

Hello,

In power bi, I would like a column calculated in dax which puts a 1 on the last action which precedes the auto-close action of the same ID.
The table is called Journal, the time column is time, the column where we find the auto-close is called action.
I put an example of what I want.
Can you help me ?
THANKS

 

 

17 Replies

  • hi MathieuF 

    try to add a calculated column like:

    Column = 
    VAR _LastTime=
        MAXX(
            FILTER(
                data,
                data[name]=EARLIER(data[name])
                    &&data[action]<>"auto-close"
            ),
            data[time]
        )
    RETURN
        IF(
            [Time]=_LastTime,
            1
        )

    it worked like:

    • MathieuF's avatar
      MathieuF
      Helper III

      Hello FreemanZ ,

      Thank you very much, I will test.
      Why does the formula include the name? Knowing that a person can have several IDs at the same time.
      I think that it is rather necessary to insert the notion of ID.
      Mat
  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi MathieuF ,

    Please try,

    Auto-close = 
    VAR _close_time = CALCULATE(MAX('Table'[Time]),'Table'[action]="auto-close",ALLEXCEPT('Table','Table'[ID]))
    VAR _result =IF('Table'[Time]=CALCULATE(MAX('Table'[Time]),'Table'[Time]<_close_time),1)
    RETURN
    _result

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

    • MathieuF's avatar
      MathieuF
      Helper III

      Hello Anonymous ,

      Thanks a lot for your help.
      Is it possible to have a 1 just on the action which precedes and not all the actions which precede.
      THANKS

       

  • Good morning,
    With the formula below, how to display only one 1; the one just after the auto-close?
    Can anyone help me?

     

    `Auto-close2 =

    VAR _close_time = CALCULATE(MAX('journal'[created_at]),'journal'[action]="auto-close",ALLEXCEPT('journal','journal'[task_id]))
    VAR _result =IF('journal'[created_at]=CALCULATE(MAX('journal'[created_at]),'journal'[created_at]<_close_time,ALLEXCEPT('journal','journal'[task_id])),1)
    RETURN
    _result`


    Thanks in advance.

    Anonymous