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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Group Rows by Relative Dates

Hello everyone,

 

I have a data table which looks like this:

 

BranchWO#Hours WorkedFirst LaborLast LaborMachine IDIndex
10N857383.134/22/20194/22/201906328015
10N8584004/24/2019 06328014
10N858394.784/24/20194/26/201906328016
50K3282827/2/20197/3/201906328017
50K331288.58/14/20198/16/201906328018
50K333123.59/10/20199/10/201906328019
70Z1725314.0811/4/201911/15/201906328020
70Z1773410.291/29/20202/5/202006328021
70Z1787610.452/20/20203/10/202006328022
70Z1795303/3/2020 06328013
70Z181030.553/30/20206/5/202006328025
70Z1819305/5/2020 0632809
70Z184316.895/18/20206/1/202006328024
70Z1848705/29/20205/29/202006328023
70Z188507.127/6/20207/17/202006328026
70Z196788.6310/20/202011/18/202006328027
70Z202715.491/22/20212/1/202106328028
70Z204044.222/10/20212/18/202106328029
60M2851312.472/17/20212/22/202106328030
60M2859103/1/2021 0632804

 

I need to group rows together and assign the resulting groups a Unique ID (per group) via a calculated column.

The grouping criteria: Where Machine ID is the same between rows, where the Date Difference between “Last Labor” and “First Labor” (between rows) is never more than 30 days +/- and exclude rows where “First Labor” and/or “Last Labor” are BLANK.

 

The desired results would look like this:

 

BranchWO#Hours WorkedFirst LaborLast LaborMachine IDIndexGroup Index
10N857383.134/22/20194/22/2019063280151516
10N8584004/24/2019 06328014 
10N858394.784/24/20194/26/2019063280161516
50K3282827/2/20197/3/201906328017171819
50K331288.58/14/20198/16/201906328018171819
50K333123.59/10/20199/10/201906328019171819
70Z1725314.0811/4/201911/15/20190632802020
70Z1773410.291/29/20202/5/2020063280212122
70Z1787610.452/20/20203/10/2020063280222122
70Z1795303/3/2020 06328013 
70Z181030.553/30/20206/5/202006328025232425
70Z1819305/5/2020 0632809 
70Z184316.895/18/20206/1/202006328024232425
70Z1848705/29/20205/29/202006328023232425
70Z188507.127/6/20207/17/20200632802626
70Z196788.6310/20/202011/18/20200632802727
70Z202715.491/22/20212/1/202106328028282930
70Z204044.222/10/20212/18/202106328029282930
60M2851312.472/17/20212/22/202106328030282930
60M2859103/1/2021 0632804 

 

I have tried everything I know to accomplish this without success and have been unable to find a solution online. Any help the community can provide would be extremely welcome!

6 REPLIES 6
v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

Is your problem solved?? If so, Would you mind accept the helpful replies as solutions? Then we are able to close the thread. More people who have the same requirement will find the solution quickly and benefit here. Thank you.

Best Regards,
Community Support Team _ kalyj

Anonymous
Not applicable

Hello @v-yanjiang-msft ,

My problem was not resolved and I've closed the project as "not possible"; though I do greatly appreciate you trying to help!

v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

According to your description, here's my solution.

Create four calculated columns.

 

Column =
IF (
    'Table'[Last Labor] = BLANK ()
        || MAXX (
            FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) + 1 ),
            'Table'[First Labor]
        )
            = BLANK (),
    BLANK (),
    IF (
        DATEDIFF (
            'Table'[Last Labor],
            MAXX (
                FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) + 1 ),
                'Table'[First Labor]
            ),
            DAY
        ) <= 30,
        1
    )
)
Column 2 =
IF (
    'Table'[Column] <> 1,
    BLANK (),
    SUMX (
        FILTER (
            'Table',
            'Table'[Index] <= EARLIER ( 'Table'[Index] )
                && MAXX (
                    FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 ),
                    'Table'[Column]
                ) <> 1
        ),
        'Table'[Column]
    )
)
Column 3 =
IF (
    [Column 2] <> BLANK (),
    [Column 2],
    IF (
        MAXX (
            FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 ),
            'Table'[Column 2]
        )
            <> BLANK (),
        MAXX (
            FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 ),
            'Table'[Column 2]
        )
    )
)
Group Index =
IF (
    [Column 3] <> BLANK (),
    CONCATENATEX (
        FILTER ( 'Table', 'Table'[Column 3] = EARLIER ( 'Table'[Column 3] ) ),
        'Table'[Index]
    ),
    IF ( 'Table'[Last Labor] <> BLANK (), CONVERT ( 'Table'[Index], STRING ) )
)

 

 Get the result.

vkalyjmsft_0-1655106402341.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi @v-yanjiang-msft ! Thank you so much for your response. I implemented the additional columns that you outlined above but I ran into a problem on column 2. When I add it to the table, loading the column takes approximately 4 hours... "Working on it". The dataset I'm applying it to is about 350,000 rows. Any ideas how the calculation time could be reduced?

Hi @Anonymous ,

Actually for column2, does not use too complex operations, mainly using a sumx function, it's even simpler than other formulas. As your sample data is too large, it does run slow. But if other formula work normally but only column2 takes approximately 4 hours, I doubt it's a coincidence, the computer freeze etc.

Best Regards,
Community Support Team _ kalyj

Anonymous
Not applicable

@v-yanjiang-msft  It is a simple operation, which is why I don't understand the slowness. Unfortunatelt, I can't reduce the size of my data.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors