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!Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!
Dear Community,
I am trying to build a function for web scrapping using a python script. I want to pass a parameter as a variable to the python script. I tried following the parameter passing formula in R script. But that is not working for python file.
Is there a way to declare the search 'query' as a parameter and have it passed through or stored as a variable to be used in each time the function is invoked?
I have also shared my code snippet for reference.
Thanks.
You need to concatenate text with & and not +
The following works fine for me:
let
Source = Python.Execute("import pandas#(lf) azureAppid='" & paramAzureAppID & "'#(lf)",
df1 = Source{[Name="df"]}[Value]
in
df1
Hi @Anonymous ,
Could you have refered to below link about Using Python in Query Editor:
https://docs.microsoft.com/en-us/power-bi/desktop-python-in-query-editor
Maybe you could just enter put the python code into the Run Python Script dialog.
Regards,
Daniel He
Thank you for your reply.
I was trying to build a function with the python script. The parameter passing is not working for the function.
But the python script is working fine when it was added as a new Step.
I was wondering if there is any way I could make the same script as a function.
Regards,
Jannatun Nahar
Hey, @Anonymous
Can you explain more about "passing as a new step"? Were you able to find a workaround to use the parameter as part of your Python script?
Thanks!
Hi @Anonymous ,
Thank you very much for your reply. I am trying to create a custom invoked function using python or R script to extract tweets in powerBI. Instead of hardcoding the search term in the original R script, I wanted to pass it as a parameter. But the code is not working in this way. I am attaching a copy of my code here :
(Name as text) as table=>
let
Source = R.Execute(" #(lf) library(twitteR)
#(lf) library(stringi)
#(lf) consumer_key <- ""abcd ""
#(lf) consumer_secret <- "" adbc ""
#(lf) access_token <- ""abcd ""
#(lf) access_secret <- ""abcd""
#(lf) setup_twitter_oauth(consumer_key, consumer_secret, access_token, access_secret)
#(lf) str1 <- ""#""
#(lf) str2 <- ""&Name&"" (passing serach term as a parameter here)
#(lf) search_term <- paste(str1,str2,sep="")
#(lf) number_of_tweets <- 100
#(lf) language <-'en'
#(lf) tweets <- searchTwitter(search_term, number_of_tweets,language)
#(lf) df_tweets <- twListToDF(tweets)
#(lf) df_tweets <- df_tweets[,c('text','favorited','favoriteCount','created','retweetCount',
'isRetweet','retweeted')]
#(lf) df_tweets$text <- stri_encode(df_tweets$text, '', 'UTF-8')"),
df_tweets1 = Source{[Name="df_tweets"]}[Value]
in
df_tweets1I am working on this for my MSC capstone project. I would really appreciate any suggestion to pass through the error.
Thanks agaian.
Can someone please confirm whether this is possible or not?
This seems to work - note that dataset2 takes the dataset1 value and multiplies it by 2:
let
Source = Python.Execute("import pandas#(lf)dataset = pandas.DataFrame([1, 2, 3])"),
dataset1 = Source{[Name="dataset"]}[Value],
dataset2 = Python.Execute("
import pandas
dataset = dataset*2
dataset.to_csv('C:/Users/arman.schwarz/dataset_to_csv.csv')", [dataset = dataset1]),
dataset3 = dataset2{[Name="dataset"]}[Value],
#"Changed Type" = Table.TransformColumnTypes(dataset3,{{"0", Int64.Type}})
in
#"Changed Type"
Vote for your favorite vizzies from the Power BI World Championship submissions!
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 57 | |
| 53 | |
| 42 | |
| 16 | |
| 16 |
| User | Count |
|---|---|
| 112 | |
| 106 | |
| 39 | |
| 36 | |
| 27 |