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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
VO
Helper I
Helper I

Python Error: references unknown variable or function 'Python.Execute'

Works in the query editor, but encounter error when I close and apply:

Failed to save modifications to the server. Error returned: 'Expression in partition 'n/a' in table 'n/a' references unknown variable or function 'Python.Execute'.'.

 

Python version 3.8.2

 

Excel file

Fibonacci
0
1
1
2
3

 

Python Script:

dataset.loc[0,'Fibonacci Python'] = 0
dataset.loc[1,'Fibonacci Python'] = 1

for i in range(2, len(dataset)):
    dataset.loc[i,'Fibonacci Python'] = dataset.loc[i-1,'Fibonacci Python'] + dataset.loc[i-2,'Fibonacci Python']

 

FibonacciFibonacci Python
00
11
11
22
33

let
Source = Excel.Workbook(File.Contents("****.xlsx"), null, true),
Fibonacci_Table = Source{[Item="Fibonacci",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(Fibonacci_Table,{{"Fibonacci", Int64.Type}}),
#"Run Python script" = Python.Execute("# 'dataset' holds the input data for this script#(lf)dataset.loc[0,'Fibonacci Python'] = 0#(lf)dataset.loc[1,'Fibonacci Python'] = 1#(lf)#(lf)for i in range(2, len(dataset)):#(lf) dataset.loc[i,'Fibonacci Python'] = dataset.loc[i-1,'Fibonacci Python'] + dataset.loc[i-2,'Fibonacci Python']",[dataset=#"Changed Type"]),
dataset = #"Run Python script"{[Name="dataset"]}[Value],
#"Changed Type1" = Table.TransformColumnTypes(dataset,{{"Fibonacci", Int64.Type}, {"Fibonacci Python", Int64.Type}})
in
#"Changed Type1"

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @VO 

 

With your provided information, I managed to do it with no error. 

g1.png

 

I'd like to suggest you go to Option > Preview features and uncheck Store dataset using enhanced metadata format. Then you need to restart Power BI to see if it works.

 

For further information, you may refer the following links.

Failed to save modifications to the server. function Python.Execute 

Using enhanced dataset metadata (preview) 

 

Best Regards

Allan

 

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

View solution in original post

5 REPLIES 5
v-alq-msft
Community Support
Community Support

Hi, @VO 

 

I wonder if you have install required Python packages and enable Python scripting in Power BI. For further information, I'd like to suggest you refer the following document.

Run Python scripts in Power BI Desktop 

 

Best Regards

Allan

 

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

Hi Allan,

 

I installed pandas, matplotlib and NumPy. Python scripting is enabled. It actually works in the query editor and gives the expected output. However, it gives an error when I am trying to close and apply the changes.

v-alq-msft
Community Support
Community Support

Hi, @VO 

 

With your provided information, I managed to do it with no error. 

g1.png

 

I'd like to suggest you go to Option > Preview features and uncheck Store dataset using enhanced metadata format. Then you need to restart Power BI to see if it works.

 

For further information, you may refer the following links.

Failed to save modifications to the server. function Python.Execute 

Using enhanced dataset metadata (preview) 

 

Best Regards

Allan

 

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

Hi @v-alq-msft 

Did it all over again, it worked. Thank you.

 

"Enabling the enhanced dataset metadata feature results in an irreversible upgrade to reports. Any Power BI reports loaded or created with Power BI Desktop, once the enhanced dataset metadata enabled, are irreversibly converted to the enhanced dataset metadat format."

Hi @v-alq-msft 

 

Unfortunately, despite unchecking & restarting. It didn't work. Same error. Did you mange to close and apply the changes (I have the same output you have shared in the query editor)? Are running it on Python version 3.8.2? Thank for the other suggestions, I will explore them.

 

Error on Close & Aply

Failed to save modifications to the server. Error returned: 'Expression in partition 'n/a' in table 'n/a' references unknown variable or function 'Python.Execute'.'.

 

Query Editor

FibonacciCapture.JPG

 

ApplyErrorCapture.JPG

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.