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
hansei
Helper V
Helper V

Curious about Table.Group aggregatedColumns function

If you group a table in the GUI

hansei_0-1656020931172.png


1/ the generated code appears as such

 

Table.Group(#"Kept First Rows", {"Claim ID"}, {{"MinPrice", each List.Min([Contract Price]), type nullable number}})

 


2/ even though the argument to the 'each' function is a table, you can rewrite the function like the following and it will always work

 

Table.Group(#"Kept First Rows", {"Claim ID"}, {{"MinPrice", each List.Min(Record.Field(_, "Contract Price")), type nullable number}})

 

 

3/ however, rewriting that same code inside a let/in block raises an error

 

Table.Group(#"Kept First Rows", {"Claim ID"}, {{"MinPrice", each let n = List.Min(Record.Field(_, "Contract Price")) in n, type nullable number}})

Expression.Error: We cannot convert a value of type Table to type Record.

 


4/ to work inside the let/in block, you need to change from Record.Field to Table.Column like this

 

Table.Group(#"Kept First Rows", {"Claim ID"}, {{"MinPrice", each let n = List.Min(Table.Column(_, "Contract Price")) in n, type nullable number}})

 


I get why #3 generates an error. I'm wondering why #2 does not...

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @hansei,

I think this should be related to the let-in structure and _ operator.
In the 'group' function, the _ operator after 'each' keyword mapping to the table type, and can be recognized and evaluated after each keyword but these operations seem not processed in the nested let-in structure. (perhaps related to Lazy and eager evaluation)

Evaluation model - PowerQuery M | Microsoft Docs

For your scenario, you can try to use the following formula to fix this issue:

Table.Group(#"Kept First Rows", {"Claim ID"}, {{"MinPrice", each let n = List.Min(_[Contract Price]) in n,  type nullable number}})

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

Hi @hansei,

I think this should be related to the let-in structure and _ operator.
In the 'group' function, the _ operator after 'each' keyword mapping to the table type, and can be recognized and evaluated after each keyword but these operations seem not processed in the nested let-in structure. (perhaps related to Lazy and eager evaluation)

Evaluation model - PowerQuery M | Microsoft Docs

For your scenario, you can try to use the following formula to fix this issue:

Table.Group(#"Kept First Rows", {"Claim ID"}, {{"MinPrice", each let n = List.Min(_[Contract Price]) in n,  type nullable number}})

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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.