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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Prathameshsable
Advocate V
Advocate V

Previous row value but for a group of ID

Hi, 

 

I have the following data in the below table -

 

IDStartEnd
B217804-06-2023 00:0904-06-2023 00:47
B217804-06-2023 00:0904-06-2023 00:47
B217804-06-2023 00:4704-06-2023 00:52
B217804-06-2023 00:5504-06-2023 01:32
B217804-06-2023 00:5504-06-2023 01:32
B704404-06-2023 01:3204-06-2023 01:36
B704404-06-2023 01:3204-06-2023 01:36
B704404-06-2023 01:3604-06-2023 01:41
B704404-06-2023 01:3604-06-2023 01:41
B116404-06-2023 02:1904-06-2023 02:24
B116404-06-2023 02:1904-06-2023 02:24
B116404-06-2023 02:2404-06-2023 02:30
B116404-06-2023 02:2404-06-2023 02:30
B135304-06-2023 03:1304-06-2023 03:29
B135304-06-2023 03:1304-06-2023 03:29
B217804-06-2023 03:3804-06-2023 03:49
B217804-06-2023 03:3804-06-2023 03:49
B217804-06-2023 03:4904-06-2023 03:50

 

The ID colum has multiple start and end datetime, where-in basically the start datestime are in sequence. The ID column is nothing but a machine ID and the start and end are the runtimes of the machine, for every set of machine, I need to get the earliest start for every set of run in one column and the machine ID in another. Like for e.g. Machine ID B2178 has 2 set of runs on the same day.

 

The Output columns :

ID MAP which is nothing but for the B2178 and group of its run, it picks up the ID & concats with the date

ID runs 1 is picking up the earliest runtime for every ID and then filling it across for the where the ID has run for a specific period.

 

I can use a previous row methodology in PQ to check if previous row is blank but I want to find something dynamic in DAX itself which can give me a column to use, I want to further use these columns in creating Matrix visuals, hence the ask. 

 

I tried working out on Earlier function, but not working. So need help on solving this one. Its a pressing issue for me, so any help on this is appreciated.

Expected Output:

IDStartEnddd-mmm-yyID MAPID runs 1
B217804-06-2023 00:0904-06-2023 00:4704-Jun-23B2178_04-Jun-23B2178_04-Jun-23 00:09
B217804-06-2023 00:0904-06-2023 00:4704-Jun-23 B2178_04-Jun-23 00:09
B217804-06-2023 00:4704-06-2023 00:5204-Jun-23 B2178_04-Jun-23 00:09
B217804-06-2023 00:5504-06-2023 01:3204-Jun-23 B2178_04-Jun-23 00:09
B217804-06-2023 00:5504-06-2023 01:3204-Jun-23 B2178_04-Jun-23 00:09
B704404-06-2023 01:3204-06-2023 01:3604-Jun-23B7044_04-Jun-23B7044_04-Jun-23 01:32
B704404-06-2023 01:3204-06-2023 01:3604-Jun-23 B7044_04-Jun-23 01:32
B704404-06-2023 01:3604-06-2023 01:4104-Jun-23 B7044_04-Jun-23 01:32
B704404-06-2023 01:3604-06-2023 01:4104-Jun-23 B7044_04-Jun-23 01:32
B116404-06-2023 02:1904-06-2023 02:2404-Jun-23B1164_04-Jun-23B1164_04-Jun-23 02:19
B116404-06-2023 02:1904-06-2023 02:2404-Jun-23 B1164_04-Jun-23 02:19
B116404-06-2023 02:2404-06-2023 02:3004-Jun-23 B1164_04-Jun-23 02:19
B116404-06-2023 02:2404-06-2023 02:3004-Jun-23 B1164_04-Jun-23 02:19
B135304-06-2023 03:1304-06-2023 03:2904-Jun-23B1353_04-Jun-23B1353_04-Jun-23 03:13
B135304-06-2023 03:1304-06-2023 03:2904-Jun-23 B1353_04-Jun-23 03:13
B217804-06-2023 03:3804-06-2023 03:4904-Jun-23B2178_04-Jun-23B2178_04-Jun-23 03:38
B217804-06-2023 03:3804-06-2023 03:4904-Jun-23 B2178_04-Jun-23 03:38
B217804-06-2023 03:4904-06-2023 03:5004-Jun-23 B2178_04-Jun-23 03:38
2 ACCEPTED SOLUTIONS

Hi @danextian - I tried this and it doesnt give me the expected results.

What I am trying to do here is if the current row of the ID matches the previous row if the ID then 'Blank' else contactenate ID & start date (format to dd-mmm-yy). Thats for the IDMap column.

The second column IDruns, just returns the earliest datetime of the IDMap column.

Please do not consider the end date in the calculation.

 

So basically in excel its a simple formula -

Considering column "E" as the ID & O as the start date - the below formulas are

IDMap =IF(E22=E21,"",E22&"_"&O22)

Output - B2178_04-Jun-23

And ID Runs1 = =IF(E2=E1,"",E2&"_"&O2&" "&TEXT(TIMEVALUE(TEXT(M2,"hh:mm")),"hh:mm"))
Output - B2178_04-Jun-23 00:09

 

Also, I have a issue in the above DAX wherein if I dynamically pick up a start and date, the above formulaes should take the take start datetime ascending as the initiation point for all its calculations? 

 

Any help here is thankful.

 

Regards,

Prathamesh

View solution in original post

Hi @Prathameshsable ,

 

Going back to my initial response, is this supposed to be another sequence? Basing on the logic that its start is not the same as the end of the previous row, it should be. If not, then how do you identify which ones are not?

 

danextian_0-1710682545202.png

Also, I have a issue in the above DAX wherein if I dynamically pick up a start and date, the above formulaes should take the take start datetime ascending as the initiation point for all its calculations? If you're trying to pick up a date from a slicer, that will not affect your calculated columns. Calculated columns and tables update only when the underlying data has been refreshed or when they've been modified and not to a change in slicer selection.

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

5 REPLIES 5
danextian
Super User
Super User

hI @Prathameshsable 

Try this calc column and work from here.

IDRuns2 =
VAR __DateTime = Table2[Start]
VAR __ID = Table2[ID]
VAR __PrevEnd =
    CALCULATE (
        MAX ( 'Table2'[End] ),
        FILTER (
            'Table2',
            'Table2'[End] <= EARLIER ( 'Table2'[Start] )
                && 'Table2'[ID] = EARLIER ( 'Table2'[ID] )
        )
    )
VAR __Table =
    FILTER (
        ADDCOLUMNS ( Table2, "@runs", IF ( __PrevEnd <> [Start], [Start] ) ),
        [ID] = __ID
    )
VAR __LastDateTime =
    MAXX ( FILTER ( __Table, [@runs] <= __Datetime ), [@runs] )
VAR __IDRuns =
    Table2[ID] & FORMAT ( __LastDateTime, "_dd-mmm-yy hh:mm" )
RETURN
    __IDRuns

Please note that your data shows 3sequences starting at 12:09, 12:55 (the end b efore this is 12:52) and 3:38 however your sample result shows just 2.

danextian_0-1710498818921.png

 

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi @danextian - I tried this and it doesnt give me the expected results.

What I am trying to do here is if the current row of the ID matches the previous row if the ID then 'Blank' else contactenate ID & start date (format to dd-mmm-yy). Thats for the IDMap column.

The second column IDruns, just returns the earliest datetime of the IDMap column.

Please do not consider the end date in the calculation.

 

So basically in excel its a simple formula -

Considering column "E" as the ID & O as the start date - the below formulas are

IDMap =IF(E22=E21,"",E22&"_"&O22)

Output - B2178_04-Jun-23

And ID Runs1 = =IF(E2=E1,"",E2&"_"&O2&" "&TEXT(TIMEVALUE(TEXT(M2,"hh:mm")),"hh:mm"))
Output - B2178_04-Jun-23 00:09

 

Also, I have a issue in the above DAX wherein if I dynamically pick up a start and date, the above formulaes should take the take start datetime ascending as the initiation point for all its calculations? 

 

Any help here is thankful.

 

Regards,

Prathamesh

Hi @Prathameshsable ,

 

Going back to my initial response, is this supposed to be another sequence? Basing on the logic that its start is not the same as the end of the previous row, it should be. If not, then how do you identify which ones are not?

 

danextian_0-1710682545202.png

Also, I have a issue in the above DAX wherein if I dynamically pick up a start and date, the above formulaes should take the take start datetime ascending as the initiation point for all its calculations? If you're trying to pick up a date from a slicer, that will not affect your calculated columns. Calculated columns and tables update only when the underlying data has been refreshed or when they've been modified and not to a change in slicer selection.

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

This helps. Thanks for your help on this topic 🙂

Hi @danextian,

 

So let me explain the first part the ID is a machine ID which kind of is a machine which is common for multiple customers, so if you see 2 same datetime entries against the machine it, they are because there are multiple customers for which the machine was functioning. Hence 2 date times. However, the data coming from excel is manually sorted in ascending order and then based on the previous row of just the machine ID (without datetime) it just sees if the previous record contains the same machine ID (e.g. machine ID = 1 had 10 entries for 10 customers, it will still be flagged as the machine ID), and once the machine ID is changed from 1 to 2, the flag will showcase machine ID =2. And for tat entire set of 10 entries for machine Id 1, it will pick up the earliest datetime of the machine ID until it changed. It could be a thing that machine id 1 was used later in the day, so it will still be counted as a separate entry. So hope it clears the doubt. 

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.