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
koogie
Regular Visitor

Inquiry about M code operation.

Hello.

I am wondering how the M code works. The code is as follows.

1. Each Table.RowCount (Table.SelectRows (# "Grouped Rows", (s) => s [TotalSales]> [TotalSales])) + 1, Int64.Type)

(s) => s [TotalSales]> [TotalSales])) + 1

I'm not sure, but in this formula, s [TotalSales] seems to work for multiple lines. [TotalSales] seems to work on a single row.

2. (s) => Table.RowCount (Table.SelectRows (# "Grouped Rows", each s [TotalSales] <[TotalSales])) + 1, Int64.Type)

Unlike number 1, in this formula, s [TotalSales] seems to act as a single row and [TotalSales] acts as multiple rows.
I'm curious about the difference between the two functions and how they work internally.
1 ACCEPTED SOLUTION
Anonymous
Not applicable

... 
each Table.RowCount (Table.SelectRows (# "Grouped Rows", (s) => s [TotalSales]> [TotalSales])) + 1, Int64.Type)

...

 

this piece of code appears to be part (argument) of a function such as Table.AddColumn or similar.

the inner part of this piece: Table.SelectRows (# "Grouped Rows", (s) => s [TotalSales]> [TotalSales])

selects all rows of the # "Grouped Rows" table (which was probably created in the previous step) that satisfy the condition that the value of column s[TotalSales] is greater than the value _ [TotalSales] of the current row to which the anonymous function each (these selected lines are then counted +1)

 

the following  is an equivalente form of the same expression:

... 
(outer) => Table.RowCount (Table.SelectRows (# "Grouped Rows", (inner) => inner[TotalSales]> outer[TotalSales])) + 1, Int64.Type)

...

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

... 
each Table.RowCount (Table.SelectRows (# "Grouped Rows", (s) => s [TotalSales]> [TotalSales])) + 1, Int64.Type)

...

 

this piece of code appears to be part (argument) of a function such as Table.AddColumn or similar.

the inner part of this piece: Table.SelectRows (# "Grouped Rows", (s) => s [TotalSales]> [TotalSales])

selects all rows of the # "Grouped Rows" table (which was probably created in the previous step) that satisfy the condition that the value of column s[TotalSales] is greater than the value _ [TotalSales] of the current row to which the anonymous function each (these selected lines are then counted +1)

 

the following  is an equivalente form of the same expression:

... 
(outer) => Table.RowCount (Table.SelectRows (# "Grouped Rows", (inner) => inner[TotalSales]> outer[TotalSales])) + 1, Int64.Type)

...

 

Thank you very much.

Thanks to that, it was well understood.

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.

Top Solution Authors
Top Kudoed Authors