cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Gorgmaster
Regular Visitor

Comparison of Values from different rows

Hey there!

 

Got a little Problem with some data.

For better understanding here an example:

 

I've got a table with time stamps of machined parts. The time stamp tells me, when the part was finished. I would like to take the time stamp of the last part as start time for the next part. So I will get a time range, during which time a part was produced. In a second tabel I can compare the time ranges to error messages. That I already solved.

 

Here is an example for the tabel, the last column should be calculated.

machinepartEnd TimeStart Time
1107:30Blank
2207:2907:22
1307:3707:30
1407:4407:37
2507:3607:29
1607:5107:44
2707:22Blank
1807:5807:51

 

I tried to find the Min-Value of a filtered list where the row of the actual value is excepted. But I didn't get to a solution.

 

Hopefully someone can help!

 

 

 

 

 

1 ACCEPTED SOLUTION

So a slight modification to the code then:

Start time =
VAR _prevTime = 'Table'[End Time]
VAR _machine = 'Table'[machine]
RETURN
    CALCULATE (
        MAX ( 'Table'[End Time] );
        FILTER ( 'Table'; 'Table'[machine] = _machine && 'Table'[End Time] < _prevTime )
    )

And just to be sure, you are trying to create a calculated column, right?

This works on the sample data you provided. If you have trouble implementing it in your model, perhaps post a more realistic dataset?

View solution in original post

4 REPLIES 4
sturlaws
Resident Rockstar
Resident Rockstar

Hi,


try this

Start time =
CALCULATE (
    MAX ( 'Table'[End Time] );
    FILTER (
        'Table';
        'Table'[machine] = EARLIER ( 'Table'[machine] )
            && 'Table'[part] < EARLIER ( 'Table'[part] )
    )
)

Hey,

thanks for the reply.

 

Unfortunately it doesn't work. I've tried the formula with the exact given table in my question. But I got in the start-column the same time as in the end column.

 

By the way, the part number isn't meant as a rank. it is only a number.

So a slight modification to the code then:

Start time =
VAR _prevTime = 'Table'[End Time]
VAR _machine = 'Table'[machine]
RETURN
    CALCULATE (
        MAX ( 'Table'[End Time] );
        FILTER ( 'Table'; 'Table'[machine] = _machine && 'Table'[End Time] < _prevTime )
    )

And just to be sure, you are trying to create a calculated column, right?

This works on the sample data you provided. If you have trouble implementing it in your model, perhaps post a more realistic dataset?

That's it!

 

Thanks a lot!

Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors