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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
jdusek92
Helper IV
Helper IV

M formula explanation - Table.SelectRows

Hello,

I have successfully applied the solution from this post.

Now I would like to understand the logic.

 

scenario:

(simplified)

  1. data table with employees ID, Month and value for the respective month
  2. correction data table with ID, correct value, "valid from month" and "valid to month"

The task is to correct the data with the values from correction table, for given ID and months

 

 

I have this M formula, that WORKS:

 

 

let
    Source = Excel.CurrentWorkbook(){[Name="kons"]}[Content],
    zmenyBuf = Table.Buffer(zmeny),
    #"Added Custom" = Table.AddColumn(Source, "NovySl", (tempNazev) => Table.SelectRows(zmenyBuf,each tempNazev [m]>= [od] and  tempNazev [m]<= [do] and tempNazev [ID]=[ID]), Value.Type(zmenyBuf)),
    #"Expanded zmeny" = Table.ExpandTableColumn(#"Added Custom", "NovySl", {"hod"}, {"NovySl.hod"})
in
    #"Expanded zmeny"

 

 

I would like to understand this part:

what is the purpose of tempNazev ? Is that just a placeholder?

 

(tempNazev) => Table.SelectRows(zmenyBuf,each tempNazev [m]>= [od] and  tempNazev [m]<= [do] and tempNazev [ID]=[ID]), Value.Type(zmenyBuf)

 

 

Warm regards,

Jakub

1 ACCEPTED SOLUTION

@jdusek92,

 

It's not a function name, it's an input parameter of the function, you may refer to tutorials belew about custom function in power query.

http://radacad.com/writing-custom-functions-in-power-query-m

https://blogs.msdn.microsoft.com/mvpawardprogram/2013/08/19/creating-power-query-functions/

 

Community Support Team _ Jimmy Tao

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

3 REPLIES 3
v-yuta-msft
Community Support
Community Support

@jdusek92,

 

Based on my understanding, this is because you use a Table.Buffer function before the add columns step. Table.Buffer will buffer a table into memory, isolating it from external changes during evaluation which means it's a temparary table and you can call it multiple times with out load table into memery again. It's very similar to a function parameter which is also not in disk memory. 

 

So this question can be converted to "When and where should we use a buffer in power query", you may refer to similar cases below:

https://community.powerbi.com/t5/Desktop/How-to-Improve-Query-Reference-performance-for-large-tables...

https://community.powerbi.com/t5/Desktop/Queries-over-large-data-tables/m-p/26783/highlight/true#M85...

 

Community Support Team _ Jimmy Tao

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

@v-yuta-msft thank you very much for your answer.

 

I am getting the idea of buffered tables. In my example the buffered table is called zmenyBuf.

 

But I am still not sure about this syntax:

 

(tempNazev) => Table.SelectRows(zmenyBuf,each tempNazev [m]>= [od] and  tempNazev [m]<= [do] and tempNazev [ID]=[ID]), Value.Type(zmenyBuf)

what is the function name of (tempNazev) => 

Could you provide any links with more information about this syntax?

 

Warm regards

 

@jdusek92,

 

It's not a function name, it's an input parameter of the function, you may refer to tutorials belew about custom function in power query.

http://radacad.com/writing-custom-functions-in-power-query-m

https://blogs.msdn.microsoft.com/mvpawardprogram/2013/08/19/creating-power-query-functions/

 

Community Support Team _ Jimmy Tao

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

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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