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
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
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

April Fabric Community Update

Fabric Community Update - April 2024

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

March 2024 PBI Gallery Image

Power BI Monthly Update - March 2024

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