Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Did you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now

Reply
PPalkowski
Helper II
Helper II

Multiple Sort Columns, Token Comma Error

In power Query I was trying to sort by using two columns and I keep getting this error.

 

Expression.SyntaxError: Toekn Comma expected.

 

 

= let
Source = Excel.Workbook(File.Contents("M:\Quarterly KPI\KPI Data.xlsx"), null, true),
ALLDATA_Sheet = Source{[Item="ALLDATA",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(ALLDATA_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"QRT", type text}, {"MONTH", type text}, {"CAT", type text}, {"TYPE", type text}, {"VALUE", Int64.Type}}),
#"Sorted Rows" = Table.Sort({{"MONTH", Order.Ascending}},{"CatSort",Order.Ascending}})
in
#"Changed Type"

1 ACCEPTED SOLUTION
dax
Community Support
Community Support

Hi PPalkowski,

Whehn you want to sort, you could refer to refer to below M code(which refer to previous step's result and sort acs)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTICYQNDS31DfUOlWJ1opSSggDFM0AhJ0AxdJUi7OYrKWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [name = _t, amount = _t, date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"name", type text}, {"amount", Int64.Type}, {"date", type date}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"date", Order.Ascending}, {"amount", Order.Ascending}})
in
    #"Sorted Rows"

You need remove }   from MONTH, and add a reference in sort function.

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
dax
Community Support
Community Support

Hi PPalkowski,

Whehn you want to sort, you could refer to refer to below M code(which refer to previous step's result and sort acs)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTICYQNDS31DfUOlWJ1opSSggDFM0AhJ0AxdJUi7OYrKWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [name = _t, amount = _t, date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"name", type text}, {"amount", Int64.Type}, {"date", type date}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"date", Order.Ascending}, {"amount", Order.Ascending}})
in
    #"Sorted Rows"

You need remove }   from MONTH, and add a reference in sort function.

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi @PPalkowski

I think you have an extra closing } after the first sorting condition in
Table.Sort({{"MONTH", Order.Ascending}} /* <- */,{"CatSort",Order.Ascending}})

Kind regards
JB

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.