Skip to content

Instantly share code, notes, and snippets.

@cbaragao
Created August 12, 2026 23:55
Show Gist options
  • Select an option

  • Save cbaragao/666b9b141516816deefefd9957783554 to your computer and use it in GitHub Desktop.

Select an option

Save cbaragao/666b9b141516816deefefd9957783554 to your computer and use it in GitHub Desktop.
ExcelChallenge1041
let
Source = Excel.CurrentWorkbook(){[Name = "Data"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source, {{"Data", type text}}),
Tx = Table.TransformColumns(
#"Changed Type",
{
"Data",
each [
Category = Text.Trim(Text.Split(_, ">"){0}),
Transaction = Text.Trim(List.Last(List.RemoveLastN(Text.Split(_, ":"), 1))),
Amt = List.Last(Text.Split(_, ":"))
]
}
),
Expand = Table.ExpandRecordColumn(
Tx,
"Data",
{"Category", "Transaction", "Amt"},
{"Category", "Transaction", "Amt"}
),
SetTypesAfterExpand = Table.TransformColumnTypes(
Expand,
{{"Category", type text}, {"Amt", type number}, {"Transaction", type text}}
),
IfThen = Table.AddColumn(
SetTypesAfterExpand,
"Amt2",
each
if [Transaction] = "Return" then
- 1 * [Amt]
else if [Transaction] = "Promotion" then
0
else
[Amt],
type number
),
#"Grouped Rows" = Table.Group(
IfThen,
{"Category"},
{{"Amount", each List.Sum([Amt2]), type number}}
),
#"Sorted Rows" = Table.Sort(#"Grouped Rows", {{"Category", Order.Ascending}})
in
#"Sorted Rows"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment