Forum Discussion

dia612's avatar
dia612
Helper IV
6 years ago
Solved

Dynamically changing name ofthe column header

Hello, In Power BI, We can dynamically change the title name  using measure in Format > Title > fx But is there a way , I can change name of the column Header also  dynamically using the measure??...
  • Anonymous's avatar
    Anonymous
    6 years ago

    Hi dia612,

    It means you can create a list with the column names you wanted, then you can invoke them in your query table with 'renamecolumns' function to dynamic rename current column names:

    Columnname stored a list of column names strings

    let
        Source = {"id","name","desc"}
    in
        Source

    Query table invokes above list to rename fields:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRU0lEyMgISxsZKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", Int64.Type}, {"Column3", Int64.Type}}),
        #"Renamed Columns" = Table.RenameColumns(#"Changed Type",List.Zip({Table.ColumnNames(#"Changed Type"),ColumnNames}))
    in
        #"Renamed Columns"

    Regards,

    Xiaoxin Sheng