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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Kobold67
New Member

Passing parameters from Power BI to Python script for the first step in a data source

The first step as data source is a Python script which collects the data from an Azure DevOps Server on-premise. In order to use the OData feed of the server I have to pass an authentication token. To make later change easier, I would like to pass the URL of the server as well as the authentication token from Power BI into the Python script.

 

Here comes a short snippet from the advanced editor:

 

let
    Source = Python.Execute("import pandas as pd#(lf)import numpy as np#(lf)import requests#(lf)import json#(lf)import os#(lf)import sys#(lf)import pathlib#(lf)import ppr

 

 

The related Python code looks like:

 

import pandas as pd
import numpy as np
import requests
import json
import os
import sys
import pathlib
import pprint
import configparser
from requests.auth import HTTPBasicAuth
from decimal import Decimal

# Read parameter from environment (Power BI) -> does not work at the moment as first step (hardcoded for now)
#ados_url = "&Text.From(ADOSServer)&"
#personal_access_token = "&Text.From(AccessToken)&"
ados_url = "http://xxx/_odata/v2.0/"
personal_access_token = "yyyyyyyyyyyyy"

 

 

There a a couple of examples available, but in these examples the parameter are used not as first step inside the data source. As soon as I try to use the parameter already within the Source= statement, the parameter are never expanded.

 

I tried up to now the following examples:

 

ados_url = """ & ADOSServer """
ados_url = '"&Text.From(ADOSServer)&"'
ados_url = "&Text.From(ADOSServer)&"

 

 

None of them worked. I got always the string after the assignment.

 

Any ideas?

 

4 REPLIES 4
koushikp
Frequent Visitor

Any other solution here? I am on the same boat.

Zaid
New Member

Hi,

Please help me with this, I am facing this same issue.

 

Thanks

amitchandak
Super User
Super User

The article does not help me. The solution is working, however the only problem at the moment is, that I like to move out the server URL and access token from the python script. Otherwise I have to re-enter this after expiration (token last for around a year) in all data sources provided from the script.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.