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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Ramh84
Frequent Visitor

Removing all the last rows below the row that had met the condition in Power Query

Hello folks,

 

I am trying to find the position of the cell in Column1 that starts with the word "Technician".

 

Once found out, I would like to delete all the below rows with respect to (above found position) and including the row found with the word "Technician". Note that the # of rows below might vary..

 

Please note that sometimes the pdf pages are corrupted, and thus, might not have pulled up the word "Technician".

In such instance, I would like to do nothing but return the nested table as is. 

Please not that I am in the process of creating a custom function so that I use it as invoking custom function later on, as I am reading the pdfs from a folder that will contains many files..

My intitial thoughts as I am trying to implement above processes is to use the following Mcode functions:


= Table.AddColumn(#"Filtered Rows", "Custom.1", each Table.RemoveLastN([Data], List.PositionOf([Data][Column1],"Technician",Occurrence.First, (x,y) => Text.StartsWith(x,y))))

However, this definately will not acheive so, as it will truncate more records/rows than what should be..

I hope that I made it clear 🙂


Appreciate your support.

Screenshot 2025-07-14 174158.png


1 ACCEPTED SOLUTION
bhanu_gautam
Super User
Super User

@Ramh84 Try using below steps

Open Power Query Editor.
Go to the "Home" tab and click on "Advanced Editor".
Define a new function as follows:

 

let
// Define the custom function
RemoveRowsAfterTechnician = (inputTable as table) as table =>
let
// Find the position of the row that starts with "Technician"
position = List.PositionOfAny(
List.Transform(inputTable[Column1], each Text.StartsWith(_, "Technician")),
{true}
),
// Check if the position is found
resultTable = if position = -1 then
inputTable
else
Table.FirstN(inputTable, position)
in
resultTable
in
RemoveRowsAfterTechnician

 

After defining the function, you can invoke it on your table.
Assuming your table is named #"Filtered Rows", you can add a new step to invoke the function:

m
let
// Your existing steps
Source = ...,
#"Filtered Rows" = ...,
// Invoke the custom function
ResultTable = RemoveRowsAfterTechnician(#"Filtered Rows")
in
ResultTable




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

2 REPLIES 2
Ramh84
Frequent Visitor

Thank you so much for your quick and accurate solution! @bhanu_gautam 

You made my day 🙂

bhanu_gautam
Super User
Super User

@Ramh84 Try using below steps

Open Power Query Editor.
Go to the "Home" tab and click on "Advanced Editor".
Define a new function as follows:

 

let
// Define the custom function
RemoveRowsAfterTechnician = (inputTable as table) as table =>
let
// Find the position of the row that starts with "Technician"
position = List.PositionOfAny(
List.Transform(inputTable[Column1], each Text.StartsWith(_, "Technician")),
{true}
),
// Check if the position is found
resultTable = if position = -1 then
inputTable
else
Table.FirstN(inputTable, position)
in
resultTable
in
RemoveRowsAfterTechnician

 

After defining the function, you can invoke it on your table.
Assuming your table is named #"Filtered Rows", you can add a new step to invoke the function:

m
let
// Your existing steps
Source = ...,
#"Filtered Rows" = ...,
// Invoke the custom function
ResultTable = RemoveRowsAfterTechnician(#"Filtered Rows")
in
ResultTable




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.

Top Kudoed Authors