Forum Discussion
PowerQuery Advanced Filtering Help
- 4 years ago
You're missing a comma at the end of your FM_Billing_Report_Sheet statement, refencing the wrong step for the Grouped Rows and needed to lose the 'in FM_Billing_Report_Sheet' at the end.
Try this, may still need some alterations but this should get you closer.
let Source = Excel.Workbook( File.Contents("C:\Users\riesc_86uyy47\Desktop\Files\Full Daily Report.xlsx"), null, true ), FM_Billing_Report_Sheet = Source{[Item = "FM_Billing_Report", Kind = "Sheet"]}[Data], #"Grouped Rows" = Table.Group( FM_Billing_Report_Sheet, {"Name"}, {{"all", each _, type table [Name = nullable text, Rate = nullable number]}} ), #"Added Custom" = Table.AddColumn( #"Grouped Rows", "Custom", each Table.AddColumn([all], "index", (all) => if all[Rate] = null then 1 else 2) ), #"Aggregated Custom" = Table.AggregateTableColumn( #"Added Custom", "Custom", {{"index", List.Distinct, "Count of index"}} ), #"Extracted Values" = Table.TransformColumns( #"Aggregated Custom", {"Count of index", each Text.Combine(List.Transform(_, Text.From), ","), type text} ), #"Filtered Rows" = Table.SelectRows( #"Extracted Values", each ([Count of index] = "1,2" or [Count of index] = "2,1") ), #"Expanded all" = Table.ExpandTableColumn(#"Filtered Rows", "all", {"Rate"}, {"Rate"}), #"Removed Other Columns" = Table.SelectColumns(#"Expanded all", {"Name", "Rate"}), #"Changed Type1" = Table.TransformColumnTypes(#"Removed Other Columns", {{"Rate", Currency.Type}}) in #"Changed Type1"This website can be very helpful for formatting and pointing out errors in code.
https://www.powerqueryformatter.com/formatter
let
Source = Excel.Workbook(File.Contents("C:\Users\riesc_86uyy47\Desktop\Files\Full Daily Report.xlsx"), null, true),
FM_Billing_Report_Sheet = Source{[Item="FM_Billing_Report",Kind="Sheet"]}[Data]
#"Grouped Rows" = Table.Group(
#"Changed Type",
{"Name"},
{{"all", each _, type table [Name = nullable text, Rate = nullable number]}}
),
#"Added Custom" = Table.AddColumn(
#"Grouped Rows",
"Custom",
each Table.AddColumn([all], "index", (all) => if all[Rate] = null then 1 else 2)
),
#"Aggregated Custom" = Table.AggregateTableColumn(
#"Added Custom",
"Custom",
{{"index", List.Distinct, "Count of index"}}
),
#"Extracted Values" = Table.TransformColumns(
#"Aggregated Custom",
{"Count of index", each Text.Combine(List.Transform(_, Text.From), ","), type text}
),
#"Filtered Rows" = Table.SelectRows(
#"Extracted Values",
each ([Count of index] = "1,2" or [Count of index] = "2,1")
),
#"Expanded all" = Table.ExpandTableColumn(#"Filtered Rows", "all", {"Rate"}, {"Rate"}),
#"Removed Other Columns" = Table.SelectColumns(#"Expanded all", {"Name", "Rate"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Removed Other Columns", {{"Rate", Currency.Type}})
in
#"Changed Type1"
in
FM_Billing_Report_Sheet
Receiving a "Token Comma expected" error on the bolded line
You're missing a comma at the end of your FM_Billing_Report_Sheet statement, refencing the wrong step for the Grouped Rows and needed to lose the 'in FM_Billing_Report_Sheet' at the end.
Try this, may still need some alterations but this should get you closer.
let
Source = Excel.Workbook(
File.Contents("C:\Users\riesc_86uyy47\Desktop\Files\Full Daily Report.xlsx"),
null,
true
),
FM_Billing_Report_Sheet = Source{[Item = "FM_Billing_Report", Kind = "Sheet"]}[Data],
#"Grouped Rows" = Table.Group(
FM_Billing_Report_Sheet,
{"Name"},
{{"all", each _, type table [Name = nullable text, Rate = nullable number]}}
),
#"Added Custom" = Table.AddColumn(
#"Grouped Rows",
"Custom",
each Table.AddColumn([all], "index", (all) => if all[Rate] = null then 1 else 2)
),
#"Aggregated Custom" = Table.AggregateTableColumn(
#"Added Custom",
"Custom",
{{"index", List.Distinct, "Count of index"}}
),
#"Extracted Values" = Table.TransformColumns(
#"Aggregated Custom",
{"Count of index", each Text.Combine(List.Transform(_, Text.From), ","), type text}
),
#"Filtered Rows" = Table.SelectRows(
#"Extracted Values",
each ([Count of index] = "1,2" or [Count of index] = "2,1")
),
#"Expanded all" = Table.ExpandTableColumn(#"Filtered Rows", "all", {"Rate"}, {"Rate"}),
#"Removed Other Columns" = Table.SelectColumns(#"Expanded all", {"Name", "Rate"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Removed Other Columns", {{"Rate", Currency.Type}})
in
#"Changed Type1"
This website can be very helpful for formatting and pointing out errors in code.
https://www.powerqueryformatter.com/formatter
- Anonymous4 years agoNot applicable
Definitely closer 🙂 I changed Name and Rate to the more accurate column headers, but still getting error below.
#"Grouped Rows" = Table.Group(
#"Changed Type",
{"DBName"},
{{"all", each _, type table [DBName = nullable text, RatingGroup = nullable number]}}"Expression.Error: The name 'Changed Type' wasn't recognized. Make sure it's spelled correctly."
- KNP4 years ago
Super User
You should have just been able to replace the entire code in the advanced editor...
In your workbook, follow the gif below.