Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
MathieuF
Helper III
Helper III

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

 

MathieuF_0-1682575625484.png

 

17 REPLIES 17
MathieuF
Helper III
Helper III

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

MathieuF_0-1699975336089.png

 

`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.

@v-cgao-msft 

MathieuF
Helper III
Helper III

Good morning,
Let me come back to you because I'm still stuck.
I am looking to put the name of the agent in the column created in front of the line Journal[action]=auto-close which follows the line where I have the agent for the same task_id.

https://drive.google.com/file/d/1j-P7F-Prw_5y-3QmV8WzE8GdApm1X5NX/view?usp=drive_link

 

MathieuF_0-1699268973692.png

Thank you

v-cgao-msft
Community Support
Community Support

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

vcgaomsft_0-1682935919032.png

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

Hello @v-cgao-msft ,

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

MathieuF_0-1682942258278.png

 

Hello @v-cgao-msft,

Can you help me ?
Mathieu

Hi @MathieuF ,

 

Please consider providing a sample file that can cover the question and give the expected output. Note that it should not contain private data.

How to provide sample data in the Power BI Forum - Microsoft Fabric Community

 

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

Hi @MathieuF ,

The link requires permission to access.

 

Best Regards,
Gao

@v-cgao-msft This should be good.

Hi @MathieuF ,

 

It seems that the key [action] field is missing from the data.

vcgaomsft_0-1686881131640.png

Please try:

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

vcgaomsft_0-1686881743256.png

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

@v-cgao-msft 

Thank you for your help, unfortunately, I have an error message:
It is not possible to determine a unique value for the "created_at" column of the "Journal" table. This can happen when a measure formula refers to a column that contains many values, without specifying an aggregation such as min, max, count, or sum to get a single result.

So I changed the query to 

 

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

 

is it good ?
Because I have no result 😞

FreemanZ
Super User
Super User

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:

FreemanZ_0-1682577215100.png

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

hi @MathieuF 

you know your dataset best. please feel free to change name to id.

@FreemanZ 

The results are not good.
I am currently having a problem accessing the table.
When I have new access, I will see what is causing the problem.
Small question, should the table be sorted?

hi @MathieuF 

what error do you get?

Sort will not change anything in most DAX occassions.

Hello @FreemanZ 
I'll screenshot the problem for you.
I will privately send you the model with the data.
Is it related to the sorting of updated-at?

MathieuF_0-1682666601948.png

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.