Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Alias Static Column

Hi everyone, 


I have a power BI table sourced via direct query that shows client codes and the related data for each. This table shows the top 10 clients and will change with diffferent filters.

 

As we cannot display the actaul client code I am after a way to have the first column of the table a column called 'Client'. This column needs to simply say client 1, client 2 etc and not change when the top 10 does.

 

Is there a way to have a fixed column with data simply showing client 1 etc in order? 
Any help is much appreciated.

 

Regards,

Jake 

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Anonymous ,

     

    Yes, you just need to make sure that your column name does not change, even if the data is refreshed, it will not affect another column, he is static and fixed.

     

    Best Regards,

    Neeko Tang

    If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly.

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    According to your description, here are my steps you can follow as a solution.

    (1) This is my test data. 

    (2)Click "transform data" to enter the power query editor, click "Advanced Editor" to copy and paste the following code, please check the steps in the right step bar.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlSK1YlWSgKTyWAyBUymgsk0MJkOJjPAZCaYzFKKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [clients = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"clients", type text}}),
        #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
        #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each "client"),
        #"Inserted Merged Column" = Table.AddColumn(#"Added Custom", "Merged", each Text.Combine({[Custom], Text.From([Index], "en-US")}, " "), type text),
        #"Removed Columns" = Table.RemoveColumns(#"Inserted Merged Column",{"Index", "Custom"}),
        #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Merged", "clients"})
    in
        #"Reordered Columns"

    (3) Then the result is as follows.

    (4)Or we can create a calculated column.

    Column = "client" & COUNTROWS(FILTER(ALLSELECTED('Table'[clients]),[clients]<=EARLIER('Table'[clients])))

    Best Regards,

    Neeko Tang

    If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Anonymous , thank you for your message.

       

      Does this work with the idea that the top 10 may change. For example if my top 10 become d, j, g ,f ..... will it still show client 1, client 2 etc in order ? 

       

      No matter what the top 10 is, I need the first column of my table to show client 1 etc in order 

       

      Regards,

      Jake 

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Anonymous ,

         

        Yes, you just need to make sure that your column name does not change, even if the data is refreshed, it will not affect another column, he is static and fixed.

         

        Best Regards,

        Neeko Tang

        If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly.