Forum Discussion
Query based on tables without relations?
Hello everyone!
I have 3 tables that are not related, and I need to get a combined query, I tried to use UNION and SELECTCOLUMNS, but it was not possible.
first table
fechaid_productid_facilityconsumoprograma
| 01-ene-22 | A | X | 10 | 5 |
| 02-ene-22 | A | X | 20 | 15 |
| 03-ene-22 | A | Y | 30 | 10 |
| 04-ene-22 | B | Y | 40 | 20 |
| 05-ene-22 | B | Z | 50 | 30 |
second table
fechaid_productid_facilityexistenciarecibido
| 01-ene-22 | A | X | 100 | 24 |
| 02-ene-22 | A | X | 200 | 56 |
| 03-ene-22 | A | Y | 300 | 76 |
| 04-ene-22 | B | Y | 400 | 45 |
| 05-ene-22 | B | Z | 500 | 56 |
third table
fechaid_facilityvolumen
| 01-ene-22 | X | 56 |
| 02-ene-22 | X | 43 |
| 03-ene-22 | Y | 45 |
| 04-ene-22 | Y | 65 |
| 05-ene-22 | Z | 21 |
expected result
fechaid_productid_facilityconsumoprogramaexistenciarecibidovolumen
| 01-ene-22 | A | X | 10 | 5 | 100 | 24 | 56 |
| 02-ene-22 | A | X | 20 | 15 | 200 | 56 | 43 |
| 03-ene-22 | A | Y | 30 | 10 | 300 | 76 | 45 |
| 04-ene-22 | B | Y | 40 | 20 | 400 | 45 | 65 |
| 05-ene-22 | B | Z | 50 | 30 | 500 | 56 | 21 |
any ideas, Thank you very much in advance.
PBIX-file: Query
Hi Cipriano ,
You can use "Merge Queries as new" in Power Query and the expand the columns you need.
Final output:
Or you can try what FreemanZ suggested to use TREATAS function which is best for use when a relationship does not exist between the tables.
You can reference the following document.
Merge queries overview - Power Query | Microsoft Learn
Virtual Relationship with TREATAS - Microsoft Power BI Community
Best Regards,
Community Support Team _ xiaosunIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- FreemanZSuper User
you can treat unrelated table columns as related ones with TREATAS function. https://dax.guide/treatas/
- v-xiaosun-msftCommunity Support
Hi Cipriano ,
You can use "Merge Queries as new" in Power Query and the expand the columns you need.
Final output:
Or you can try what FreemanZ suggested to use TREATAS function which is best for use when a relationship does not exist between the tables.
You can reference the following document.
Merge queries overview - Power Query | Microsoft Learn
Virtual Relationship with TREATAS - Microsoft Power BI Community
Best Regards,
Community Support Team _ xiaosunIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.