Forum Discussion
Remove duplicate rows from the table based on condition and summarize
- 2 years ago
In Power Query, you can filter your data first then group it. Here's a sample code that works against your sample data and expected outcome.
let
Source = Excel.Workbook(File.Contents("C:\Users\aliom\OneDrive\Desktop\Book1.xlsx"), null, true),
Table1_Table = Source{[Item="Table1",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(Table1_Table, {
{"Sale ID", Int64.Type}, {"Date", Int64.Type}, {"Place", type text}, {"Gender", type text}, {"Revenue", Int64.Type}
}),// Filter rows where Gender is Female or where Date is not 2024
#"Filtered Rows" = Table.SelectRows(#"Changed Type", each [Gender] = "Female" or [Date] <> 2024),// Group by Sale ID, Date, and all other columns
#"Grouped Rows" = Table.Group(#"Filtered Rows", {"Sale ID", "Date", "Place", "Gender"}, {
{"Total Revenue", each List.Sum([Revenue]), type number}
})
in
#"Grouped Rows"
In Power Query, you can filter your data first then group it. Here's a sample code that works against your sample data and expected outcome.
let
Source = Excel.Workbook(File.Contents("C:\Users\aliom\OneDrive\Desktop\Book1.xlsx"), null, true),
Table1_Table = Source{[Item="Table1",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(Table1_Table, {
{"Sale ID", Int64.Type}, {"Date", Int64.Type}, {"Place", type text}, {"Gender", type text}, {"Revenue", Int64.Type}
}),
// Filter rows where Gender is Female or where Date is not 2024
#"Filtered Rows" = Table.SelectRows(#"Changed Type", each [Gender] = "Female" or [Date] <> 2024),
// Group by Sale ID, Date, and all other columns
#"Grouped Rows" = Table.Group(#"Filtered Rows", {"Sale ID", "Date", "Place", "Gender"}, {
{"Total Revenue", each List.Sum([Revenue]), type number}
})
in
#"Grouped Rows"