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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Tofe
Frequent Visitor

crear una tabla de una relacion de otras dos

Hola a todos, quiero crear una relacion entre dos tablas de la siguiente manera, mi primer tabla tiene los siguientes datos,

Tofe_0-1647356511683.png y la segunda tiene,

Tofe_1-1647356557381.png entonces quiero tomar el articulo, que lo busque que la tabla 2 y luego regrese a la tabla uno tome fecha de facturacion y vea en que rango de fechas entra, en este caso para el articulo 1111396 encontro dos coincidencias pero la fecha facturacion solo esta en el segundo intervalo de fechas, 

Tofe_2-1647356722017.pngpor lo tanto quiero que mi tabla resulte sea mi tabla1, mas la coincidencia de la tabla2 con respecto al material

Tofe_3-1647356752363.png, alguna idea de como podria hacerlo en power BI? les agradezco mucho a todos.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Tofe ,

 

I suggest you to use Merge function in Power Query Editor and then add code to filter your merged table.

Click Merge Queries > Merge Queries as New > select key columns [Material] and [Client] by Ctrl + Left click . 

1.png

Then Expand [vigenica de], [vigenica a] and [costo unitario] from second table.

Finally, add below filter code in Advanced Editor to filter table dynamiclly.

...
    #"Filtered Rows" = Table.SelectRows(#"Expanded Second", each ([Invoice Date] >= [Second.vigencia de] and [Invoice Date] <= [Second.vigencia a]))
...

The Whole M code:

let
    Source = Table.NestedJoin(First, {"Material", "Client"}, Second, {"Material", "Cliente"}, "Second", JoinKind.LeftOuter),
    #"Expanded Second" = Table.ExpandTableColumn(Source, "Second", {"vigencia de", "vigencia a", "costo unitario"}, {"Second.vigencia de", "Second.vigencia a", "Second.costo unitario"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Second", each ([Invoice Date] >= [Second.vigencia de] and [Invoice Date] <= [Second.vigencia a])),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Second.vigencia de", "Second.vigencia a"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Second.costo unitario", "costo unitario"}})
in
    #"Renamed Columns"

Result:

 1.png

 

Best Regards,
Rico Zhou

 

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

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @Tofe ,

 

I suggest you to use Merge function in Power Query Editor and then add code to filter your merged table.

Click Merge Queries > Merge Queries as New > select key columns [Material] and [Client] by Ctrl + Left click . 

1.png

Then Expand [vigenica de], [vigenica a] and [costo unitario] from second table.

Finally, add below filter code in Advanced Editor to filter table dynamiclly.

...
    #"Filtered Rows" = Table.SelectRows(#"Expanded Second", each ([Invoice Date] >= [Second.vigencia de] and [Invoice Date] <= [Second.vigencia a]))
...

The Whole M code:

let
    Source = Table.NestedJoin(First, {"Material", "Client"}, Second, {"Material", "Cliente"}, "Second", JoinKind.LeftOuter),
    #"Expanded Second" = Table.ExpandTableColumn(Source, "Second", {"vigencia de", "vigencia a", "costo unitario"}, {"Second.vigencia de", "Second.vigencia a", "Second.costo unitario"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Second", each ([Invoice Date] >= [Second.vigencia de] and [Invoice Date] <= [Second.vigencia a])),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Second.vigencia de", "Second.vigencia a"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Second.costo unitario", "costo unitario"}})
in
    #"Renamed Columns"

Result:

 1.png

 

Best Regards,
Rico Zhou

 

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

Hola, Muchas gracias, se parece mucho a lo que estaba haciendo, solo que en ambos intentos cuando continuo con lo que necesito, me deja de reconocer la fecha, sabria usted por que y como podria solucionar?

Tofe_0-1647962945301.png

Tofe_2-1647967046117.png

 

 

 

Anonymous
Not applicable

Hi @Tofe ,

 

You seem to use Group by Funtion in next step. However your reply and screenshot are in Spanish in my side. So it is hard for me to understand your next step clearly. Could you share a sample file with me and show me a screenshot with the result you want? It will make me easier to find the solution.

 

Best Regards,
Rico Zhou

 

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

lbendlin
Super User
Super User

Depending on the size of your dataset you may get away with using LOOKUPVALUE() for this.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.