Quantcast
Channel: Question about necessity of buffering tables when referencing tables twice but with one of them just for the column names
Viewing all articles
Browse latest Browse all 3

Question about necessity of buffering tables when referencing tables twice but with one of them just for the column names

$
0
0

Sometimes you buffer a table if you reference the same step/table twice. Quite often enough, one of these functions that reference said table will be Table.ColumnNames. It seems quite expensive to buffer the whole table when only columns names may be needed again.  

So question is: In this scenario is it necessary to buffer the table? 

(Do/Can column names automatically get buffered when table is evaluated?)

I also give an example to help with this question (a subset of above scenario):

Let's say I want to add a column which is a simple function of another other column, but I also want to put those columns next to each other. I also do not want to hard code the other columns names in the table. 

I could write:

let
    //Should I buffer table in step below?? - table gets referenced twice in steps: AddZ and ColNames
    Source = #table(
        {"A".."Y"},
        {{1..25}}),
    AddZ = Table.AddColumn(Source,"Z",each [C]+100), 
    ColNames = List.Buffer(Table.ColumnNames(Source)),
    ReorderedList  = List.InsertRange(
        ColNames,
        List.PositionOf(
            ColNames,"C",
            Occurrence.First)+1,
        {"Z"}),
    ReorderedTable =  Table.ReorderColumns(AddZ, ReorderedList)   
in
    ReorderedTable

but I could also write:

let
    Source = #table(
        {"A".."Y"},
        {{1..25}}),
    #"Split Column by Delimiter" = Table.SplitColumn(Source, "C", each {_,_ + 100}, {"C","Z"})
in
    #"Split Column by Delimiter"

The second is smaller and I think has much better performance (but I don't actually know if this is the case). 




Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images