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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Combinar tablas con diferentes nombres de colums

Hola

Tengo dos fuentes:

1 - con A, B, C como etiquetas de columnas

2 - con A, B, D como etiquetas de columnas

Quiero como salida: A, B, (C o D)

El C o D está condicionado a la Columna B

Ambas fuentes son empujadas desde mi CRM en una base periódica en un formato XLSX. Y uso como fuente una carpeta.

¿Cómo debo proceder? ¿Crear 2 fuentes?

Gracias

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hola @fred_gc ,

¿Qué te parece esto:

let
    Source = Folder.Files("C:\xxx\xxx\xxx\xxx"),
    #"Added Custom" = Table.AddColumn(Source, "Workbook", each Excel.Workbook(File.Contents([Folder Path]&"\"&[Name]), null, true)),
    #"Expanded Workbook" = Table.ExpandTableColumn(#"Added Custom", "Workbook", {"Name", "Data", "Item", "Kind", "Hidden"}, {"Name.1", "Data", "Item", "Kind", "Hidden"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Workbook", each ([Kind] = "Table")),
    #"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows",{"Name", "Folder Path", "Data"}),
    #"Expanded Data" = Table.ExpandTableColumn(#"Removed Other Columns", "Data", {"A", "B", "C", "D"}, {"A", "B", "C", "D"}),
    #"Added Custom1" = Table.AddColumn(#"Expanded Data", "C/D", each if [B] = "B1" then [C] else [D]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"C", "D"}),
    #"Filtered Rows1" = Table.SelectRows(#"Removed Columns", each ([#"C/D"] <> null))
in
    #"Filtered Rows1"

cd.JPG

BTW, archivo .pbix adjunto.

Saludos

Icey

Si este post ayuda,entonces considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

View solution in original post

4 REPLIES 4
Icey
Community Support
Community Support

Hola @fred_gc ,

¿Qué te parece esto:

let
    Source = Folder.Files("C:\xxx\xxx\xxx\xxx"),
    #"Added Custom" = Table.AddColumn(Source, "Workbook", each Excel.Workbook(File.Contents([Folder Path]&"\"&[Name]), null, true)),
    #"Expanded Workbook" = Table.ExpandTableColumn(#"Added Custom", "Workbook", {"Name", "Data", "Item", "Kind", "Hidden"}, {"Name.1", "Data", "Item", "Kind", "Hidden"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Workbook", each ([Kind] = "Table")),
    #"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows",{"Name", "Folder Path", "Data"}),
    #"Expanded Data" = Table.ExpandTableColumn(#"Removed Other Columns", "Data", {"A", "B", "C", "D"}, {"A", "B", "C", "D"}),
    #"Added Custom1" = Table.AddColumn(#"Expanded Data", "C/D", each if [B] = "B1" then [C] else [D]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"C", "D"}),
    #"Filtered Rows1" = Table.SelectRows(#"Removed Columns", each ([#"C/D"] <> null))
in
    #"Filtered Rows1"

cd.JPG

BTW, archivo .pbix adjunto.

Saludos

Icey

Si este post ayuda,entonces considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

amitchandak
Super User
Super User

@fred_gc , En primer lugar, anexe estas dos tablas. Va a columnas A,B,C,D

https://radacad.com/append-vs-merge-in-power-bi-and-power-query

A continuación, puede escribir una columna de condición en Power Query o DAX

Ejemplo

M

E- Si [B] - "ABC" entonces [C] más [D]

Dax

E á if([B]- "ABC" ,[C] ,[D])

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

Gracias por tu respuesta.

No estaba en mi primer problema: Como estoy usando una carpeta donde se almacenan todos mis XLXS (2 tipos de archivo generados cada mes) me pregunto cómo dans este tipo de origen de datos (carpeta i puede importar archivos con diferente estructura.

@fred_gc , Puede importar archivos desde una carpeta, deben tener la misma estructura

Ejemplo

https://powerbi.microsoft.com/en-us/blog/combining-excel-files-hosted-on-a-sharepoint-folder/

https://insightsoftware.com/blog/power-bi-load-data-from-folder/

Para una estructura diferente de la misma carpeta podría tener código en M

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors
Top Kudoed Authors