Power Query Problems

How to Return Rows After the Last 8 in Power Query

Olivia MillerOlivia Miller Nov 10, 2026 868 views

Question details

The user wants to extract all rows that appear after the final occurrence of the number 8 in a specific column of a Power Query table.

How to Return Rows After the Last 8 in Power Query
Product
Excel Power Query
Device & OS
not provided
Scenario
Filtering and transforming a dataset based on the dynamic position of a specific target value.
Observed behavior
The user needs a method to isolate rows following the last instance of the target number, preferably using the standard graphical interface rather than relying solely on custom M code.
Before you start

Ensure your data is properly formatted as a table and loaded into the Power Query Editor before applying these transformation steps.

Solution 1Recommended

Extract Rows Using the Power Query User Interface

A step-by-step method using standard Power Query interface buttons like Index, Conditional Columns, and Grouping.

This method avoids custom programming by utilizing helper columns to mark the target value and group the data accordingly.

1
Add an Index Column

Navigate to the 'Add Column' tab in the Power Query ribbon and click 'Index Column' to create a unique identifier for each row.

2
Add a Conditional Column

Click 'Conditional Column' under the Add Column tab. Set a rule: if your target column (e.g., 'Number') equals 8, then output the value from the 'Index' column.

3
Fill Down the Conditional Values

Select your newly created conditional column, go to the 'Transform' tab, click 'Fill', and choose 'Down'. This assigns the index of the number 8 to all subsequent rows until the next 8 appears.

4
Group and Sort the Data

Group the table by this conditional column without aggregating. Then, sort the grouped results in descending order and keep only the first row, which represents the final cluster of data.

5
Clean Up and Filter

Drill down into the remaining table data. Filter out the top row where the Number actually equals 8, and remove all temporary helper columns to leave only your desired dataset.

Extract Rows Using the Power Query User Interface
No Coding Required: This method relies entirely on the visual interface, making it perfect for users who are not comfortable writing custom M code formulas.
Free Microsoft Office alternative

Handle Your Spreadsheets Efficiently with WPS Office

While Power Query offers specific data modeling functions in Microsoft Excel, WPS Office provides a lightweight, highly compatible, and free alternative for your daily spreadsheet processing. Easily filter, sort, and analyze your data without heavy processing overhead.

  1. 1. Download the Installer: Visit the official WPS Office website to download the free installation package for your operating system.
  2. 2. Install WPS Office: Run the downloaded file and follow the simple on-screen instructions to complete the setup in minutes.
  3. 3. Open Your Spreadsheets: Launch WPS Spreadsheet and open your existing Excel workbooks to seamlessly continue your data filtering and analysis.
Free to download and use for document creation and data analysis.Fully compatible with Microsoft Excel formats including .xlsx, .xls, and .csv files.Lightweight software design ensures fast loading times even when handling large datasets.Familiar user interface requires no learning curve for users switching from other Office suites.
QA img-9

Frequently Asked Questions

Can I extract rows after a different text or number value in Power Query?

Yes, you can easily replace the number 8 in both the Conditional Column setup or the M code formula with any other number, text string, or date you need to use as your reference point.

Why use an Index column for the user interface method?

The Index column provides a unique row identifier. When combined with a Conditional Column and the Fill Down tool, it creates a unique grouping ID for each section of data separated by your target value.

What happens if the target value does not exist in the dataset?

If using the UI method, the grouping step may fail to segment the data as expected. With the M code List.PositionOf function, it will return an error or null if the value isn't found, which is why it is recommended to ensure the value exists or wrap the step in error-handling logic.

Is M Code faster than the user interface method for this task?

Generally, yes. A single M code function like Table.RemoveFirstN is more computationally efficient and requires fewer processing steps than adding multiple helper columns and grouping data, resulting in faster query refresh times.