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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
AnetaK
Helper V
Helper V

Power Query rank strange behaviour

Hi,

I added a column with rank in PQ (using Table.AddIndexColumn function), based on the value of a date .

AnetaK_0-1665509126142.png

 

Then I added this value to a different table (merge).

When I look into the data I see it shows good values.

AnetaK_1-1665509353532.png


But when I expand this column then the rank numbers are different.

AnetaK_2-1665509442912.png

 

Anyone knows why?

4 REPLIES 4
AnetaK
Helper V
Helper V

I created an example.

 

This is a table, where I added a rank.

Null is #1.

AnetaK_0-1665510141116.png

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTIw1AMiIwMjI6VYHaiQsR4QoQqZ6gERihCYkYRpQhKaCbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, Date = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"Date", type date}}),
#"Sorted Rows" = Table.Sort(#"Changed Type",{{"Category", Order.Ascending}, {"Date", Order.Ascending}}),
#"Grouped Rows" = Table.Group(#"Sorted Rows", {"Category"}, {{"Count", each _, type table [Category=nullable text, Date=nullable date]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Count],"Rank",1,1)),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Category", "Count"}),
#"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Category", "Date", "Rank"}, {"Category", "Date", "Rank"})
in
#"Expanded Custom"

 

 

Then I added this column by merge to another table, and null is #4.

Weird.

AnetaK_1-1665510197475.png

 

But one step earlier it is #1.

AnetaK_0-1665510591600.png

 

 

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTIw1AMiIwMjI6VYHaiQsR4QoQqZ6gERihCYkYRpQhKaCbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, Date = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"Date", type date}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Category", "Date"}, #"Table with rank", {"Category", "Date"}, "Table (2)", JoinKind.LeftOuter),
#"Expanded Table" = Table.ExpandTableColumn(#"Merged Queries", "Table (2)", {"Rank"}, {"Rank"})
in
#"Expanded Table"

 

 

Hi @AnetaK 

Thanks for reaching out to us.

>> Then I added this column by merge to another table, and null is #4.  ...  But one step earlier it is #1.

I create a sample file, the rank of the null line is always 1,

vxiaotang_0-1665558999027.png

vxiaotang_1-1665559019563.png

 

Best Regards,

Community Support Team _Tang

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

Hm?

Did you use my M code?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.