cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jdusek92 Regular Visitor
Regular Visitor

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

Accepted Solutions
Community Support Team
Community Support Team

Re: M formula explanation - Table.SelectRows

@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.

3 REPLIES 3
Community Support Team
Community Support Team

Re: M formula explanation - Table.SelectRows

@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.

jdusek92 Regular Visitor
Regular Visitor

Re: M formula explanation - Table.SelectRows

@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

 

Community Support Team
Community Support Team

Re: M formula explanation - Table.SelectRows

@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.