Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Print the column values with multiple times like concatenate

Hi there, 

 

I am looking for the output similar to one above using either Power Query or DAX.

 

Cheers,

  • Anonymous's avatar
    Anonymous
    6 years ago

    this code dynamically applies logic to all columns subsequent to the first.

     

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTICYgOlWJ1oMMsYzoOwdJRMwDwTKM8YzDOFqjRSio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [key = _t, ABC = _t, XYZ = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"ABC", Int64.Type}, {"XYZ", Int64.Type}}),
        cols=Table.ColumnNames(#"Changed Type"),
        nCols=List.Count(cols),
    
       #"Added Custom" = Table.AddColumn(#"Changed Type", "out", (r)=>
           Text.AfterDelimiter( Text.Combine(List.Transform({1..nCols-1}, (c)=> Text.Repeat(":|"&cols{c},Record.FieldValues(r){c}) )),":|"))
    
    in
        #"Added Custom"

     

     

     

     

  • Anonymous's avatar
    Anonymous
    6 years ago

    Hi v-juanli-msft 

     

    I have found a solution for the same in DAX and it works well.

     

    Cheers,

    Rutika

10 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

     

     

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTICYgOlWJ1oMMsYzoOwdJRMwDwTKM9YKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [key = _t, ABC = _t, XYZ = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"ABC", Int64.Type}, {"XYZ", Int64.Type}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "out", each Text.AfterDelimiter(Text.Repeat(":|ABC",[ABC]) &Text.Repeat(":|XYZ",[XYZ]),":|"))
    in
        #"Added Custom"

     

     

     

     

    if you don't need a more general solution that doesn't rigidly depend on the name of the columns,
    an unclear point for me is the fact that only a few lines must have text. but it is not explained which or by what criteria to choose
     
    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Anonymous 

       

      the logic is it should be based on the value present in the respective column, if it is 0 then no need to display concatenate value.

      • Anonymous's avatar
        Anonymous
        Not applicable

        "the logic is it should be based on the value present in the respective column, if it is 0 then no need to display concatenate value."

        why, then, is the second line empty?