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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Anonymous
Not applicable

Pass Sample size in SQL Query

I use the below SQL query from Power BI. Instead of manually giving in the sample size as 30, is there a way to dynamically pass the user input as the sample size.
for example, if I have a parameter, wher user can give in the number of rows, Can I pass this value inside the Advanced Editor as the sample size?

SELECT DISTINCT event_id, event_date

FROM my_table TABLESAMPLE(30 ROWS) REPEATABLE(1)

1 ACCEPTED SOLUTION

@Anonymous Sure, create a Text parameter. In my case I called mine Rows. Make sure it is Text. Then you can edit your query like the following:

let
    Rows = Rows,
    Source = Sql.Database("localhost\MSSQLSERVERDEV", "AdventureWorksDW2019", [Query="SELECT DISTINCT AccountKey, ParentAccountKey FROM DimAccount TABLESAMPLE(" & Rows & " ROWS) REPEATABLE(1)"])
in
    Source

So, the first line grabs the Rows parameter and put it in the query as a value called Rows. That is then used in the SQL Query by appending it inside the query.

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

@Anonymous Yes, you can use a parameter for that.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler  Could you please show how the parameter can be passed inside the SELECT query?

@Anonymous Sure, create a Text parameter. In my case I called mine Rows. Make sure it is Text. Then you can edit your query like the following:

let
    Rows = Rows,
    Source = Sql.Database("localhost\MSSQLSERVERDEV", "AdventureWorksDW2019", [Query="SELECT DISTINCT AccountKey, ParentAccountKey FROM DimAccount TABLESAMPLE(" & Rows & " ROWS) REPEATABLE(1)"])
in
    Source

So, the first line grabs the Rows parameter and put it in the query as a value called Rows. That is then used in the SQL Query by appending it inside the query.

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.