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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
SACooper
Helper II
Helper II

Variables in Query

Hi All,

 

I'm using a powerbi dataset to load, transform and then store reports in a SQL database (Via [R]). I'm wondering if its possible to set up a simple variable that can be called to create a different temporary table in the SQL statement.

 

i.e. for the first dataset being transformed have the variable set to 1 so the sql statement could be "... INSERT INTO Table" & VARIABLE & " ............" and then with the second query the variable would need to be incremented by 1 and so on for however many queries I end up having to load this way....

 

 

4 REPLIES 4
Anonymous
Not applicable

Hi @SACooper ,

 

You can create a parameter for this for changing data source dynamically.

Please kindly refer to the solutions below

Change the Data Source dynamically in Power BI using Parameters - SqlSkull

 

 

Best Regards,

Stephen Tao

 

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

jbwtp
Memorable Member
Memorable Member

Hi @SACooper,

 

Something like this?

let
    Source = {1..10},
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Added Custom" = Table.AddColumn(#"Converted to Table", "Custom", each "... INSERT INTO Table" & Text.From([Column1]) & " ............"),
    
    SqlCall = (q as text)=> "Called SQL database with " & q,

    #"Added SqlCall" = Table.AddColumn(#"Added Custom", "SqlCall", each SqlCall([Custom]))
in
    #"Added SqlCall"

 

Cheers,

John

Hi @jbwtp 

 

Apologises for the delay a couple of issues arose at work which took up my time. If i'm reading your solution correctly we'd still need to know the upper limit of the number of queries, or would it not matter if the range was to 100 with only 50 queries (at that point in time)

How do you know when to stop sending "INSERT INTO" statements?

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.