Forum Discussion
Power Query
There are 2 SQL queries SQL1 and SQL2, doesn't have a common column between them wated join the queries and result of second query should display as column AS I need dynamic value to build the report, Please share the expertise. tried with case statement however it's a giving static value, I need dynamic value as a column
Hi SDonga ,
If SQL1 and SQL2 don't share a common column but you still want to combine them in a way where the result of SQL2 appears as a static column alongside SQL1, you can achieve this by using a cross join or by adding a static column using Power Query after retrieving both queries separately.Since you're looking for a static value from SQL2 to appear with every row of SQL1, one common method is to load SQL2 as a separate query, extract the specific value you need (e.g., using Table.FirstValue), and then add it as a new custom column to SQL1 in Power Query. If you're working purely in SQL and your database supports it, you can simulate this by selecting the desired value from SQL2 and embedding it in SQL1’s SELECT clause using a subquery. For example: SELECT col1, col2, (SELECT TOP 1 static_value FROM SQL2) AS StaticColumn FROM SQL1. This way, the value from SQL2 is treated as a constant across all rows of SQL1.
5 Replies
- rohit1991Super User
Hi SDonga ,
If SQL1 and SQL2 don't share a common column but you still want to combine them in a way where the result of SQL2 appears as a static column alongside SQL1, you can achieve this by using a cross join or by adding a static column using Power Query after retrieving both queries separately.Since you're looking for a static value from SQL2 to appear with every row of SQL1, one common method is to load SQL2 as a separate query, extract the specific value you need (e.g., using Table.FirstValue), and then add it as a new custom column to SQL1 in Power Query. If you're working purely in SQL and your database supports it, you can simulate this by selecting the desired value from SQL2 and embedding it in SQL1’s SELECT clause using a subquery. For example: SELECT col1, col2, (SELECT TOP 1 static_value FROM SQL2) AS StaticColumn FROM SQL1. This way, the value from SQL2 is treated as a constant across all rows of SQL1.
- PwerQueryKeesSuper User
Please share:
- All your M-Code
Not just the part you are struggling with, but also the part leading up to it. An error or issue often has its root cause earlier on. - (a sample of) your data . Preferably not a screenshot (or at least an easy readable screenshot).
So I can attempt to replicate your issues or question and possibly solve it quicker.
- All your M-Code
- v-saisrao-msftCommunity Support
Hi SDonga
I hope this information is helpful. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, please Accept it as a solution and give it a 'Kudos' so others can find it easily.
Thank you. - v-saisrao-msftCommunity Support
Hi SDonga,
May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.
Thank you.
- v-saisrao-msftCommunity Support
Hi SDonga,
We haven’t heard back from you regarding your issue. If it has been resolved, please mark the helpful response as the solution and give a ‘Kudos’ to assist others. If you still need support, let us know.
Thank you.