Table.AlternateRows

Table

Keeps and drops alternating groups of rows based on a repeating keep/drop pattern.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Table.AlternateRows(table as table, offset as number, keepNext as number, dropNext as number) as table

Parameters

NameTypeRequiredDescription
tabletableYesThe table to process.
offsetnumberYesThe zero-based index of the first row to start the keep/drop pattern.
keepNextnumberYesThe number of consecutive rows to keep in each cycle.
dropNextnumberYesThe number of consecutive rows to drop after each keep group.

Return Value

tableA table containing only the kept rows according to the alternating pattern.

Remarks

Table.AlternateRows applies a repeating keep/drop pattern to the rows of a table. Starting at the zero-based offset row, it keeps keepNext consecutive rows, then discards dropNext consecutive rows, and repeats this pattern until the end of the table. All rows before offset are unconditionally kept.

This function is primarily useful when consuming data that has a fixed repeating structure — for example, raw exports where every second row is a separator, or flat files where every Nth row contains a record header that should be discarded after parsing. For purely row-count-based skipping or selection, Table.Skip and Table.FirstN are simpler alternatives.

Be aware that Table.AlternateRows does not typically fold to the data source, so it will be evaluated locally. For large datasets, consider pre-filtering at the source before applying this function.

Examples

Example 1: Sample every other row (keep 1, drop 1)

let
    Source = #table(
        {"OrderID", "CustomerName", "Product"},
        {
            {1, "Alice",   "Widget A"},
            {2, "Bob",     "Gadget B"},
            {3, "Charlie", "Widget C"},
            {4, "Alice",   "Gadget D"},
            {5, "Diana",   "Widget A"},
            {6, "Bob",     "Thingamajig E"},
            {7, "Charlie", "Gadget B"},
            {8, "Diana",   "Widget C"}
        }
    )
in
    Table.AlternateRows(Source, 0, 1, 1)
Result
OrderID
CustomerName
Product
11AliceWidget A
23CharlieWidget C
35DianaWidget A
47CharlieGadget B

Example 2: Keep first 2 rows, drop 1, then repeat

Table.AlternateRows(
    #table({"Row"}, {{"A"}, {"B"}, {"SEP"}, {"C"}, {"D"}, {"SEP"}, {"E"}, {"F"}}),
    0, 2, 1
)
Result
Row
1A
2B
3C
4D
5E
6F

Example 3: Use offset to preserve a header before the pattern starts

Table.AlternateRows(
    #table({"Row"}, {{"Header"}, {"Data1"}, {"SEP"}, {"Data2"}, {"SEP"}}),
    1, 1, 1
)
Result
Row
1Header
2Data1
3Data2

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks