Variable in a Power BI query
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have a SQL query to get the data into Power BI. For example:
select a,b,c,d from table1
where a in ('1111','2222','3333' etc.)
However, the list of variables ('1111','2222','3333'
etc.) will change every day so I would like the SQL statement to be updated before refreshing the data. Is this possible?
Ideally, I would like to keep a spreadsheet with a list of a
values (in this example) so before refresh, it will feed those parameters into this script.
Another problem I have is the list will have a different nr of parameters so the last variable needs to be without a comma.
Another option I was considering is to run the script without the where a in ('1111','2222','3333' etc.)
and then load the spreadsheet with a list of those a's and filter the report down based on that list however this will be a lot of data to import into Power BI.
It's my first post ever, although I was sourcing help from Stackoverflow for years, so hopefully, it's all clear.
powerbi powerquery
add a comment |
I have a SQL query to get the data into Power BI. For example:
select a,b,c,d from table1
where a in ('1111','2222','3333' etc.)
However, the list of variables ('1111','2222','3333'
etc.) will change every day so I would like the SQL statement to be updated before refreshing the data. Is this possible?
Ideally, I would like to keep a spreadsheet with a list of a
values (in this example) so before refresh, it will feed those parameters into this script.
Another problem I have is the list will have a different nr of parameters so the last variable needs to be without a comma.
Another option I was considering is to run the script without the where a in ('1111','2222','3333' etc.)
and then load the spreadsheet with a list of those a's and filter the report down based on that list however this will be a lot of data to import into Power BI.
It's my first post ever, although I was sourcing help from Stackoverflow for years, so hopefully, it's all clear.
powerbi powerquery
I haven't used Power BI for a while. When you say"However, the list of variables ('1111','2222','3333' etc.)..."
, do you mean aList
as in Power Query/M? If so, you can just useText.Combine(someList, ",")
, which will effectively turn{"1","2","3"}
to"1,2,3"
. If you needed'
before and after each list item, you could try something likeList.Transform(someList, each "'" & Text.From(_) & "'")
, then callText.Combine
. All of this will give you a concatenated string, which you can then put into your SQL query.
– chillin
Jan 4 at 22:45
add a comment |
I have a SQL query to get the data into Power BI. For example:
select a,b,c,d from table1
where a in ('1111','2222','3333' etc.)
However, the list of variables ('1111','2222','3333'
etc.) will change every day so I would like the SQL statement to be updated before refreshing the data. Is this possible?
Ideally, I would like to keep a spreadsheet with a list of a
values (in this example) so before refresh, it will feed those parameters into this script.
Another problem I have is the list will have a different nr of parameters so the last variable needs to be without a comma.
Another option I was considering is to run the script without the where a in ('1111','2222','3333' etc.)
and then load the spreadsheet with a list of those a's and filter the report down based on that list however this will be a lot of data to import into Power BI.
It's my first post ever, although I was sourcing help from Stackoverflow for years, so hopefully, it's all clear.
powerbi powerquery
I have a SQL query to get the data into Power BI. For example:
select a,b,c,d from table1
where a in ('1111','2222','3333' etc.)
However, the list of variables ('1111','2222','3333'
etc.) will change every day so I would like the SQL statement to be updated before refreshing the data. Is this possible?
Ideally, I would like to keep a spreadsheet with a list of a
values (in this example) so before refresh, it will feed those parameters into this script.
Another problem I have is the list will have a different nr of parameters so the last variable needs to be without a comma.
Another option I was considering is to run the script without the where a in ('1111','2222','3333' etc.)
and then load the spreadsheet with a list of those a's and filter the report down based on that list however this will be a lot of data to import into Power BI.
It's my first post ever, although I was sourcing help from Stackoverflow for years, so hopefully, it's all clear.
powerbi powerquery
powerbi powerquery
edited Jan 7 at 8:06


vestland
4,12932456
4,12932456
asked Jan 3 at 9:53
DynielDyniel
61
61
I haven't used Power BI for a while. When you say"However, the list of variables ('1111','2222','3333' etc.)..."
, do you mean aList
as in Power Query/M? If so, you can just useText.Combine(someList, ",")
, which will effectively turn{"1","2","3"}
to"1,2,3"
. If you needed'
before and after each list item, you could try something likeList.Transform(someList, each "'" & Text.From(_) & "'")
, then callText.Combine
. All of this will give you a concatenated string, which you can then put into your SQL query.
– chillin
Jan 4 at 22:45
add a comment |
I haven't used Power BI for a while. When you say"However, the list of variables ('1111','2222','3333' etc.)..."
, do you mean aList
as in Power Query/M? If so, you can just useText.Combine(someList, ",")
, which will effectively turn{"1","2","3"}
to"1,2,3"
. If you needed'
before and after each list item, you could try something likeList.Transform(someList, each "'" & Text.From(_) & "'")
, then callText.Combine
. All of this will give you a concatenated string, which you can then put into your SQL query.
– chillin
Jan 4 at 22:45
I haven't used Power BI for a while. When you say
"However, the list of variables ('1111','2222','3333' etc.)..."
, do you mean a List
as in Power Query/M? If so, you can just use Text.Combine(someList, ",")
, which will effectively turn {"1","2","3"}
to "1,2,3"
. If you needed '
before and after each list item, you could try something like List.Transform(someList, each "'" & Text.From(_) & "'")
, then call Text.Combine
. All of this will give you a concatenated string, which you can then put into your SQL query.– chillin
Jan 4 at 22:45
I haven't used Power BI for a while. When you say
"However, the list of variables ('1111','2222','3333' etc.)..."
, do you mean a List
as in Power Query/M? If so, you can just use Text.Combine(someList, ",")
, which will effectively turn {"1","2","3"}
to "1,2,3"
. If you needed '
before and after each list item, you could try something like List.Transform(someList, each "'" & Text.From(_) & "'")
, then call Text.Combine
. All of this will give you a concatenated string, which you can then put into your SQL query.– chillin
Jan 4 at 22:45
add a comment |
1 Answer
1
active
oldest
votes
I would create a new Query to read the "a values" from your spreadsheet. I would set the Load To / Import Data option to Only Create Connection (to avoid duplicating the data).
Then in your SQL query I would remove the where clause. With that gone you actually don't need to write custom SQL at all - just select the table/view from the Navigation UI.
Then from the the "table1" query I would add a Merge Queries step, connecting to the "a values" Query on the "a" column, using the Join Type: Inner. The resulting rows will be only those with a matching "a" column value (similar to your current SQL where clause).
Power Query wont be able to send this to your SQL Server as a single query, so it will first select all the rows from table1. But it is still fairly quick and efficient.
Thank you Mike. I did this in slightly different way. Load SQL without the where clause. Then load spreadsheet with the list and make relationship. And finally unfiltered blanks on the report level (to remove the not matching rows). Works fine and no need to tweak anything. Next time I run this report just click refresh and it will load the new data, spreadsheet and perform the same way.
– Dyniel
Jan 11 at 14:19
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54019856%2fvariable-in-a-power-bi-query%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I would create a new Query to read the "a values" from your spreadsheet. I would set the Load To / Import Data option to Only Create Connection (to avoid duplicating the data).
Then in your SQL query I would remove the where clause. With that gone you actually don't need to write custom SQL at all - just select the table/view from the Navigation UI.
Then from the the "table1" query I would add a Merge Queries step, connecting to the "a values" Query on the "a" column, using the Join Type: Inner. The resulting rows will be only those with a matching "a" column value (similar to your current SQL where clause).
Power Query wont be able to send this to your SQL Server as a single query, so it will first select all the rows from table1. But it is still fairly quick and efficient.
Thank you Mike. I did this in slightly different way. Load SQL without the where clause. Then load spreadsheet with the list and make relationship. And finally unfiltered blanks on the report level (to remove the not matching rows). Works fine and no need to tweak anything. Next time I run this report just click refresh and it will load the new data, spreadsheet and perform the same way.
– Dyniel
Jan 11 at 14:19
add a comment |
I would create a new Query to read the "a values" from your spreadsheet. I would set the Load To / Import Data option to Only Create Connection (to avoid duplicating the data).
Then in your SQL query I would remove the where clause. With that gone you actually don't need to write custom SQL at all - just select the table/view from the Navigation UI.
Then from the the "table1" query I would add a Merge Queries step, connecting to the "a values" Query on the "a" column, using the Join Type: Inner. The resulting rows will be only those with a matching "a" column value (similar to your current SQL where clause).
Power Query wont be able to send this to your SQL Server as a single query, so it will first select all the rows from table1. But it is still fairly quick and efficient.
Thank you Mike. I did this in slightly different way. Load SQL without the where clause. Then load spreadsheet with the list and make relationship. And finally unfiltered blanks on the report level (to remove the not matching rows). Works fine and no need to tweak anything. Next time I run this report just click refresh and it will load the new data, spreadsheet and perform the same way.
– Dyniel
Jan 11 at 14:19
add a comment |
I would create a new Query to read the "a values" from your spreadsheet. I would set the Load To / Import Data option to Only Create Connection (to avoid duplicating the data).
Then in your SQL query I would remove the where clause. With that gone you actually don't need to write custom SQL at all - just select the table/view from the Navigation UI.
Then from the the "table1" query I would add a Merge Queries step, connecting to the "a values" Query on the "a" column, using the Join Type: Inner. The resulting rows will be only those with a matching "a" column value (similar to your current SQL where clause).
Power Query wont be able to send this to your SQL Server as a single query, so it will first select all the rows from table1. But it is still fairly quick and efficient.
I would create a new Query to read the "a values" from your spreadsheet. I would set the Load To / Import Data option to Only Create Connection (to avoid duplicating the data).
Then in your SQL query I would remove the where clause. With that gone you actually don't need to write custom SQL at all - just select the table/view from the Navigation UI.
Then from the the "table1" query I would add a Merge Queries step, connecting to the "a values" Query on the "a" column, using the Join Type: Inner. The resulting rows will be only those with a matching "a" column value (similar to your current SQL where clause).
Power Query wont be able to send this to your SQL Server as a single query, so it will first select all the rows from table1. But it is still fairly quick and efficient.
answered Jan 5 at 5:28


Mike HoneyMike Honey
11.7k11331
11.7k11331
Thank you Mike. I did this in slightly different way. Load SQL without the where clause. Then load spreadsheet with the list and make relationship. And finally unfiltered blanks on the report level (to remove the not matching rows). Works fine and no need to tweak anything. Next time I run this report just click refresh and it will load the new data, spreadsheet and perform the same way.
– Dyniel
Jan 11 at 14:19
add a comment |
Thank you Mike. I did this in slightly different way. Load SQL without the where clause. Then load spreadsheet with the list and make relationship. And finally unfiltered blanks on the report level (to remove the not matching rows). Works fine and no need to tweak anything. Next time I run this report just click refresh and it will load the new data, spreadsheet and perform the same way.
– Dyniel
Jan 11 at 14:19
Thank you Mike. I did this in slightly different way. Load SQL without the where clause. Then load spreadsheet with the list and make relationship. And finally unfiltered blanks on the report level (to remove the not matching rows). Works fine and no need to tweak anything. Next time I run this report just click refresh and it will load the new data, spreadsheet and perform the same way.
– Dyniel
Jan 11 at 14:19
Thank you Mike. I did this in slightly different way. Load SQL without the where clause. Then load spreadsheet with the list and make relationship. And finally unfiltered blanks on the report level (to remove the not matching rows). Works fine and no need to tweak anything. Next time I run this report just click refresh and it will load the new data, spreadsheet and perform the same way.
– Dyniel
Jan 11 at 14:19
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54019856%2fvariable-in-a-power-bi-query%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I haven't used Power BI for a while. When you say
"However, the list of variables ('1111','2222','3333' etc.)..."
, do you mean aList
as in Power Query/M? If so, you can just useText.Combine(someList, ",")
, which will effectively turn{"1","2","3"}
to"1,2,3"
. If you needed'
before and after each list item, you could try something likeList.Transform(someList, each "'" & Text.From(_) & "'")
, then callText.Combine
. All of this will give you a concatenated string, which you can then put into your SQL query.– chillin
Jan 4 at 22:45