Forum Discussion

JustDavid's avatar
JustDavid
Helper IV
1 year ago
Solved

ReplaceValue of each Table Record

PQ Gurus,

 

As you can see, I have a Table on each record.

 

What I'd like to accomplish (if possible) is to do via Table.ReplaceValue( ... , each ... , Replacer.ReplaceText() ) on each of the table record under the column field [Full Description], without expanding. In other words, I'd like to achieve the replace value first before expanding the tables.

 

The [Full Description] text has a RegEx of ##### - ####.* - VariousLength.

 

So the logic that I want to do here is that for each of the table record, on on the "preview" [Full Description] replace the 'old text' by the string that's coming from LEFT([Full Description], Text.PositionOf([Full Description], "-") of the 2nd occurance, with the 'new text' as empty string

 

After I've able to do the above, only then I'd expand the tables of each record

 

PowerBI file 

  • Kind of tough since you force someone to create an example and don't show desired results. Hopefully I have understood you well enough that you can adapt this code to your real problem.

     

    BTW, I really don't understand your stated logic. An example of before and after would clarify that, but you can probably change the logic in the code below to suit your requirements.

     

    Your file is not useful since the data source is not included.

     

    But try something like the code below, which will transform each table in your column of tables before you expand them:

     

    Before:

     

     

     

     

    let
    
    //Replace Source with your table that has a column populated by Tables
        Source = Table.FromColumns({{Table9,Table10,Table11}}, type table[Table=table]),
    
    //Transform each table according to your stated logic
    //you may need to modify this as I probably mis-understood what you require
        replace = Table.TransformColumns(Source,{    
            {"Table", (t)=>Table.ReplaceValue(
                t,
                each [Full Description],
                null,
                (x,y,z)=>List.Skip(Text.Split(y,"-"),2){0},
                {"Full Description"})
            }
        })
    in
        replace

     

     

     

    After:

     

     

7 Replies

  •  

    As you can see, I have a Table on each record.

     

    These are not records, these are list items (values in a column)

     

    Consequently, you need to use List.Transform.

  • Kind of tough since you force someone to create an example and don't show desired results. Hopefully I have understood you well enough that you can adapt this code to your real problem.

     

    BTW, I really don't understand your stated logic. An example of before and after would clarify that, but you can probably change the logic in the code below to suit your requirements.

     

    Your file is not useful since the data source is not included.

     

    But try something like the code below, which will transform each table in your column of tables before you expand them:

     

    Before:

     

     

     

     

    let
    
    //Replace Source with your table that has a column populated by Tables
        Source = Table.FromColumns({{Table9,Table10,Table11}}, type table[Table=table]),
    
    //Transform each table according to your stated logic
    //you may need to modify this as I probably mis-understood what you require
        replace = Table.TransformColumns(Source,{    
            {"Table", (t)=>Table.ReplaceValue(
                t,
                each [Full Description],
                null,
                (x,y,z)=>List.Skip(Text.Split(y,"-"),2){0},
                {"Full Description"})
            }
        })
    in
        replace

     

     

     

    After: