Forum Discussion
yashsam
Jun 21, 2022Copper Contributor
Power Query: create sql dynamic match on multiple columns
Hi, I am looking to fetch data from DB using SQL containing a dynamic match on 5 columns from an input table in power query. Let me explain in details.
Say I have a table like the below one where user inputs to filter the data from SQL DB on multiple values. I am looking to write a SQL with a WHERE clause that is a combination of all the below matches.
| City | Store | Category | Line |
| Chennai | |||
| Chennai | A100 | B5 | |
| A100 | B9 | ||
| B6 | |||
| B6 | 102 | ||
| 500 | |||
| 607 | |||
| London | B6 | ||
| A200 | 600 |
SELECT city, store, category, line
FROM sample_table
I am only working with PQ for about 2 weeks now, excuse my lack of knowledge if this is something straight forward. Thanks in advance.
6 Replies
- yashsamCopper ContributorThanks for offering to help 🙂
SELECT * city, store, category, line
FROM sample_table
WHERE city = 'Chennai'
OR city & store & category = 'ChennaiA100B5'
Looking to add one condition per row
In this case I understand the rows returned by the second condition is a subset of the first one. But it I expect a minimum of 30 different combinations when going live. Any of the fields could be left blank.
- yashsamCopper ContributorBump.. need to solve this quickly