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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

Delete Rows with Criteria – applied case

Hello, I hope you can help me with the following:

For context, I have a database of trips, so I have columns for bus ID, dates, times, and so on, as shown below (I'll trim the number of columns for practicality):

 

Bus_ID

Date

Scheduled_TimeDep

Calculate_TimeDep

Index

AYM229

27/04/2023

08:00:00

08:05:00

0

FQC453

27/04/2023

08:21:00

-

1

FQC453

27/04/2023

08:24:00

08:30:00

2

LNE817

27/04/2023

08:54:00

08:59:00

3

 

As can be seen, some trips have their time adjusted with respect to the scheduled time (whether for earlier or later), which in theory generates duplicates of the same trip, as can be seen in rows 1 and 2 of the Index.

 

What I would like is to be able to compare the rows with the same ID and remove one of these based on criteria, resulting in a table like this:

Bus_ID

Date

Scheduled_TimeDep

Calculate_TimeDep

Index

AYM229

27/04/2023

08:00:00

08:05:00

0

FQC453

27/04/2023

08:24:00

08:30:00

2

LNE817

27/04/2023

08:54:00

08:59:00

3

 

Initially I was thinking of comparing the rows in a column and then raising an error on the row to be removed and then using "Table.RemoveRowsWithErrors".

 

To compare the rows, I have tried using what some call "Shift" to compare rows with respect to their position using the index column (the idea is to compare it with the previous row), but due to the number of rows and columns it takes too long.

The codebase of what I thought to call the value of the previous row is this:

 

let
    Source = BBDD,
    #"Add Index" = Table.AddIndexColumn(BBDD, "Index", 0, 1, Int64.Type),
    #"Add ID2" = Table.AddColumn(#"Add Index", "ID_Previus", each if [Index]>0 then #"Add Index"[Bus_ID]{[Index]-1} else null)
in
    #"Add ID2"

 

 

I appreciate it if someone has already faced a similar problem can help me.

3 REPLIES 3
m_dekorte
Resident Rockstar
Resident Rockstar

Hi @Anonymous,

 

Try adding a boolean filter with something like this:

 

let
    BusID = List.Buffer( BBDD[Bus_ID] ),
    Source = BBDD,
    t = Table.FromColumns(
        Table.ToColumns( BBDD ) &
        {
            List.Transform(
                List.Zip( {BusID, List.Skip( BusID, 1)} ),
                each _{0} = _{1}
            )
        }, Table.ColumnNames( BBDD ) & { "Check" }
    )
in
    t

 

 

m_dekorte_0-1682616882737.png

Ps. If this helps solve your query please mark this post as Solution, thanks!

Anonymous
Not applicable

Hi, @m_dekorte 

Thank you very much for your solution
Sorry to reply so late

As I see that solution works in that example and I guess with little data. The drawback I have is that the database has about 63000 data per month. And when carrying out the process that you propose, it takes a long time (normally each step takes a maximum of 2 minutes, and in that case it took almost 2 hours and did not finish), and since I hope to carry out the process for the data of a complete year, the amount of data will be much higher.

I have noticed that in the lower right part, where the process load size is shown (I don't know if I am mentioning it correctly), it usually ends up at 33.9MB, but when performing the step of comparing the two rows it can go up to 1.3GB.

I appreciate if with these details you know of an alternative solution

Hi @Anonymous 

 

Sorry to hear that didn't work for you, see if this does a better job

let
    Source = BBDD,
    GroupLocal = Table.Group( Source, {"Bus_ID"}, 
        {
            {"t", each Table.LastN( _, 1), type table [Bus_ID=nullable text, Date=nullable text, Scheduled_TimeDep=nullable text, Calculate_TimeDep=nullable text, Index=nullable text]}
        }, GroupKind.Local 
    ),
    ExpandTbl = Table.ExpandTableColumn(GroupLocal, "t", List.Skip( Table.ColumnNames( Source), 1 ))
in
    ExpandTbl

 

Returns the same result, but doesn't require an Index or list operation.

m_dekorte_0-1683343228286.png

 

Ps. If this helps solve your query please mark this post as Solution, thanks!

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.