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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.