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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. 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])

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
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

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors