Assuming an Excel table named TableSource
1/ Click somewhere is that table > Go to Data tab > From Table/Range (Power Query Editor opens)
2/ From the Home tab > Advanced Editor > Select all > Replace with the following M code
let
Source = Excel.CurrentWorkbook(){[Name="SourceTable"]}[Content],
ChangedTypes = Table.TransformColumnTypes(Source,
{{"Invoice No.", type text}, {"Item No.", Int64.Type}, {"Group", type text}}
),
GroupedRows = Table.Group(ChangedTypes, {"Invoice No."},
{"InvoiceTable", each _, type table}
),
RemovedOtherColumns = Table.SelectColumns(GroupedRows,{"InvoiceTable"}),
AddedKeep = Table.AddColumn(RemovedOtherColumns, "Keep", each
List.Contains([InvoiceTable][Group],"Commodity"),
type logical
),
FilteredRows = Table.SelectRows(AddedKeep, each [Keep]),
CombinedTables = Table.Combine(FilteredRows[InvoiceTable])
in
CombinedTables
3/ Click Done at the bottom of the Advanced Editor window
4/ Click Close & Load (top left of the Power Query Editor)
Sample available here