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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
harinik
Frequent Visitor

Find the earliest success request

Hello all,

 

I need to filter or flag the earliest requests that resulted in success. For example a meter id has 2 update requests. First request on 2023-03-10 12:40:34 and its status is "Success". The second update request is at 2023-03-10 15:34:23 and its status is also "Success". Now I want to consider only the first update request and ignore the second request row. Suppose the first update request resulted in "Failure", then it should consider the second update request as the earliest successful request. Here is the sample data

meter idrequest idtyperequest datestatusearliest datedate  Consider
100A1AUpdate2023-03-10 12:40success2023-03-10 12:401
100A1BUpdate2023-03-10 15:50Success2023-03-10 12:400
200B1CUpdate2023-03-15 10:20Failure2023-03-15 14:300
200B1DUpdate2023-03-15 14:30success2023-03-15 14:301


I did a DAX code for this as follows:

earliest success date = VAR request_type = 'table_update'[type]
                                     VAR meterid = 'table_update'[meter_id]
                                     RETURN
                                     MINX(
                                              FILTER('table_update','table_update'[meter_id]=meterid && table_update'[type]=request_type &&   'table_update'[status]="Success"),
                        'table_update'[request_date]  )

To flag the earliest success request: I create another calculated column:
date consider = IF('table_update'[request_date] = 'table_update'[earliest success date],1,0)

But when I implement this code I get the below result:

meter idrequest idtyperequest datestatusearliest datedate Consider
100A1AUpdate2023-03-10 12:40Success2023-03-10 12:401
100A1BUpdate2023-03-10 15:50Success2023-03-10 12:400
200B1CUpdate2023-03-15 10:20Failure2023-03-15 10:201
200B1DUpdate2023-03-15 14:30Success2023-03-15 10:200

Instead I need the earliest success date for meter id 200B to be 2023-03-15 14:30 as it is the first success. 
What am I missing? Could anyone please point me what is missing from this piece of code. Please.
Thank you very much.


1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @harinik 
Please try Calculated Column

date consider =
INT (
    'table_update'[request_date]
        = MAXX (
            FILTER (
                CALCULATETABLE (
                    'table_update',
                    ALLEXCEPT ( 'table_update', 'table_update'[meter_id], 'table_update'[type] )
                ),
                'table_update'[status] = "Success"
            ),
            'table_update'[request_date]
        )
)

 

View solution in original post

4 REPLIES 4
tamerj1
Super User
Super User

Hi @harinik 
Please try Calculated Column

date consider =
INT (
    'table_update'[request_date]
        = MAXX (
            FILTER (
                CALCULATETABLE (
                    'table_update',
                    ALLEXCEPT ( 'table_update', 'table_update'[meter_id], 'table_update'[type] )
                ),
                'table_update'[status] = "Success"
            ),
            'table_update'[request_date]
        )
)

 

Hi,
Thanks for quick reply. I tried this and now I get

meter idrequest idtyperequest datestatusdate Consider
100A1AUpdate2023-03-10 12:40Success0
100A1BUpdate2023-03-10 15:50Success1
200B1CUpdate2023-03-15 10:20Failure0
200B1DUpdate2023-03-15 14:30Success0

 

But I need to flag the first success request. so in this case request id 1A and 1D should have the [date consider] = 1 and request id 1B and 1C should have [date consider] = 0

@harinik 

Just need to change the MAXX to MINX. However, I'm wondering why D1 did not receive 1!!

date consider =
INT (
    'table_update'[request_date]
        = MINX (
            FILTER (
                CALCULATETABLE (
                    'table_update',
                    ALLEXCEPT ( 'table_update', 'table_update'[meter_id], 'table_update'[type] )
                ),
                'table_update'[status] = "Success"
            ),
            'table_update'[request_date]
        )
)

@tamerj1 ,


Yes, I changed to MINX. Also there was another value besides the status column that also needs to be checked.

meter idrequest idtyperequest datestatusvaluedate Consider
100A1AUpdate2023-03-10 12:40Successclose1
100A1BUpdate2023-03-10 15:50Successclose0
200B1CCupdate2023-03-15 10:20Successopen1
200B1CUpdate2023-03-15 10:20Failureclose0
200B1DUpdate2023-03-15 14:30Successclose0

 

So, I changed the code to :

date consider_US = INT(
                     'table_update'[request_date]
                     = MINX(
                            FILTER(
                                CALCULATETABLE(
                                    'table_update',
                                    ALLEXCEPT('table_update','table_update'[meter_id],'table_update'[type],'table_update'[status])
                                ),
                                'table_update'[status]="Success"&&'table_update'[value]="close"
                            ),
                            'table_update'[request_date]
                     )
)
 
Now i get:

meter idrequest idtyperequest datestatusvaluedate Consider
100A1AUpdate2023-03-10 12:40Successclose1
100A1BUpdate2023-03-10 15:50Successclose0
200B1CCupdate2023-03-15 10:20Successopen0
200B1CUpdate2023-03-15 10:20Failureclose0
200B1DUpdate2023-03-15 14:30Successclose1

 

🙂 

Thanks for the solution.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Users online (8,633)