Forum Discussion

TechR21's avatar
TechR21
Helper V
3 years ago

Replacing column names with dynamic values from another table

Hello,

 

I have following data and tables.

 

 Tables "ticketsfirsttab", "phonefirsttab", and "phonesecondtab" containing data about tickets, and (phone)numbers

 

 

 

Table "details" contains some metadata including the title of the fields referenced in previous tables:

 

What I'd like to be able to do is query data from the first 3 tables using the Title values from details table. These title values in table "details"can change in future so Im looking for a dynamic solution and not hard coded.

 

So it should be something like this:

 

I tried with rename columns but cant seem to make it work. Also because I need to pick the correct value based on the group in the details table.

 

Any idea?

 

5 Replies

  • Hi,

    As per our understanding, you want dynamic Columns where Column name should change based on another Tables Columns Values.

    In order reproduce your requirement we have created two test Tables , Table1 and Table 2 as shown in the below screenshot,

     

    Then Navigate to Power Query Editor where add first column as Fieldname,

    For the Table2 open Advanced Editor and Insert below this line with Source Variable,

     

     #"Renamed Columns" = Table.RenameColumns(#"Source",Table.ToRows(Table1))    

    in

        #"Renamed Columns"

     

    Now when we change the Column FCODE to FCode changed this will automatically reflect changes in another table header as well.

     

     

     

     

    If this answer helps, please mark it as Accepted Solution so it would help others to find the solution.

     

    Thanks!

    Inogic Professional Services

    An expert technical extension for your techno-functional business needs

    Power Platform/Dynamics 365 CRM

    Drop an email at [email protected]

    Service:  http://www.inogic.com/services/ 

    Power Platform/Dynamics 365 CRM Tips and Tricks:  http://www.inogic.com/blog/

    • TechR21's avatar
      TechR21
      Helper V

      when adding the renamed columns line i get following error:

       

      • TechR21's avatar
        TechR21
        Helper V

        i managed to get rid of the error but I dont have any result after, still the same column names

         

         

  • #"Renamed Columns" = Table.RenameColumns(Source , Table.ToRows(Table.SelectColumns(Table.AddColumn(Table2, "ID2", each "customfield_" & Text.From([ID])) , {"ID2", "cfname"})) , MissingField.Ignore)

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

    • TechR21's avatar
      TechR21
      Helper V

      Doesnt work. Doesnt give an error message but I dont see any results