Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
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)
Solved! Go to 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.
@Anonymous Yes, you can use a parameter for that.
@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.
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 40 | |
| 36 | |
| 34 | |
| 31 | |
| 27 |
| User | Count |
|---|---|
| 136 | |
| 103 | |
| 66 | |
| 65 | |
| 56 |