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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
abderrazak
Frequent Visitor

Change From Python to M query

Hello I made a power bi project but during this project I used 2 python scripts; the problem is that I discovered after that standard gateway does not support python so I have to change these 2 scripts or convert them i really need your support

 

 

 first script Python : 

 

# 'dataset' holds the input data for this script
import pandas as pd
DX= pd.DataFrame(dataset.loc[:,])
AAA = []
for i in range(0, len(DX)):
if(DX['stock initial'][i] > 0):
var = DX['CONSO'][i]
AAA.append(var)
else:
var = var + DX['CONSO'][i]
AAA.append(var)
DX['cumul Consommation']=AAA

result : 

 

abderrazak_0-1637665422279.png

 

 

 

 

second script python 

 

 

# 'dataset' holds the input data for this script
import pandas as pd
DX= pd.DataFrame(dataset.loc[:,])
AAA = []
for i in range(0, len(DX)):
if(DX['stock initial'][i] > 0):
var = DX['stock initial'][i] + DX['Livr_prevue'][i]-DX['CONSO'][i]
AAA.append(var)
else:
var = var + DX['Livr_prevue'][i]-DX['CONSO'][i]
AAA.append(var)
DX['stock Final']=AAA

result : 

abderrazak_1-1637665529875.png

 

 

thnks for ur support 

 

1 REPLY 1
lbendlin
Super User
Super User

You can replace these scripts with List.Accumulate()  .

 

Please provide sanitized sample data that fully covers your issue. Paste the data into a table in your post or use one of the file services. Please show the expected outcome.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.