Forum Discussion

VO's avatar
VO
Helper I
6 years ago
Solved

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"

5 Replies

  • v-alq-msft's avatar
    v-alq-msft
    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.

    • VO's avatar
      VO
      Helper I

      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.