Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
pa2021
Frequent Visitor

How to transpose Columns beginning with "LOT" in Power Query

Hello,

 

We have a data set coming from csv files which are combined. These files will have new columns whose names will begin with "LOT". How would I go about dynamically transposing these new columns as they come in?

 

I manually transposed one, but I'm not sure how to do that for future ones...

 

 

let
    Fonte = Folder.Files("Path"),
    #"Arquivos Ocultos Filtrados1" = Table.SelectRows(Fonte, each [Attributes]?[Hidden]? <> true),
    #"Invocar Função Personalizada1" = Table.AddColumn(#"Arquivos Ocultos Filtrados1", "Transformar Arquivo", each #"Transformar Arquivo"([Content])),
    #"Colunas Renomeadas1" = Table.RenameColumns(#"Invocar Função Personalizada1", {"Name", "Nome da Origem"}),
    #"Outras Colunas Removidas1" = Table.SelectColumns(#"Colunas Renomeadas1", {"Nome da Origem", "Transformar Arquivo"}),
    #"Coluna de Tabela Expandida1" = Table.ExpandTableColumn(#"Outras Colunas Removidas1", "Transformar Arquivo", Table.ColumnNames(#"Transformar Arquivo"(#"Arquivo de Amostra"))),
    #"Tipo Alterado" = Table.TransformColumnTypes(#"Coluna de Tabela Expandida1",{{"Nome da Origem", type text}, {"IDADE_SEM", Int64.Type}, {"VIAB_TAB", Int64.Type}, {"LOTE_163", Int64.Type}, {"MEDIA", Int64.Type}}),
    #"Linhas Filtradas" = Table.SelectRows(#"Tipo Alterado", each Text.EndsWith([Nome da Origem], ".csv")),
    #"Somente as Colunas Selecionadas Foram Transformadas em Linhas" = Table.Unpivot(#"Linhas Filtradas", {"LOTE_163"}, "Atributo", "Valor")
in
    #"Somente as Colunas Selecionadas Foram Transformadas em Linhas"

 

 Thank you!

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

@pa2021 You do that by doing the unpivot the other way round - "Unpivot other columns" 

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

@pa2021 You do that by doing the unpivot the other way round - "Unpivot other columns" 

It worked, but I had to tweak it so as to allow for dynamic columns that will be added to the table down the road.

 

Thank you!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.