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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
torsten_FO
Helper I
Helper I

Report refresh starts "python.execute" command two times!

Hi all,

I use a small python script directly in an empty Table with "Python.Execute(...)" command. This script send data into a Database.

When I start a refresh in Power Query Editor, the script send only one dataset into the DB. It works fine.

But, If I start a refresh into the report, the script send two datasets into the DB! 

I have inserted the Execute command into a small table:

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKk7NS4lPSSxJjC/Jj3dxUoqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Snap_Shot = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Snap_Shot", type text}}),
    #"Send SnapShot" = Python.Execute("import pyodbc
username = 'USER'
password = 'PASS'
conn = pyodbc.connect('Driver={SQL Server};'
                      'Server=SERVER;'
                      'Database=Bestandsueberpruefung;'
                      'Trusted_Connection=yes;'
                      'uid=%s;pwd=%s' %(username, password))
cursor = conn.cursor()
cursor.execute('''
               INSERT INTO t_bemerkung (bemerkung, id_matnr)
               VALUES
               ('value from python', 3)
               ''')
conn.commit()
conn.close()")
in
    #"Send SnapShot"

 

 

PBI_PyEx.png

 

What is wrong???

Thanks

 

 

1 REPLY 1
v-yadongf-msft
Community Support
Community Support

Hi @torsten_FO ,

 

Here's a blog which might be helpful to solve your problems:

Automate Your Power BI Dataset Refresh with Python - Pivotal BI

 

Best regards,

Yadong Fang

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

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.