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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
RicardoSchmidt
Regular Visitor

Looping with balance

Hello everyone!


Need some help to transform something I've made in VBA to turn into M.

 

Table1 - Production per order (one value per order)

OrderProduction (tons)Production (meters)
495200112303100
49782035420
499200132009210

 

Table 2 - Orders with the delivery dates and quantities ordered (many values per order)

 

OrderDelivery dateQtd (tons)Qtd (meters)
4952001Feb/10/228002016
4952001Mar/10/225001260
4978203Feb/10/225018
4992001Apr/25/22200576
4992001Apr/30/2210002878
4992001Jul/15/227502159
4992001Aug/05/2230008634

 

I need to merge them into a table with my orders and distributing the total produces into the months ordered and if in the last item it is above can bring the total or can bring the ordered, but if it's below it needs to bring whats was produced. Considering all the deliveries. The result is like below.

 

OrderDelivery dateQtd (tons)Qtd (meters)Production (tons)Production (meters)
4952001Feb/10/2280020168002016
4952001Mar/10/2250012604301084
4978203Feb/10/2250185018
4992001Apr/25/22200576200576
4992001Apr/30/221000287810002878
4992001Jul/15/2275021597502159
4992001Aug/05/223000863412503597

 

I just splitted the total production into the delivery dates and making a balance in the end.


Is there anyway to make it in Power Query? 

 

Thanks

1 ACCEPTED SOLUTION
Manoj_Nair
Solution Supplier
Solution Supplier

@RicardoSchmidt 

This can be done using DAX as shown below. I have done the "Tons" part. If the solution meets your expectation, please let me know so that I can share the final PBIX file

Manoj_Nair_0-1669934469093.png

 

View solution in original post

1 REPLY 1
Manoj_Nair
Solution Supplier
Solution Supplier

@RicardoSchmidt 

This can be done using DAX as shown below. I have done the "Tons" part. If the solution meets your expectation, please let me know so that I can share the final PBIX file

Manoj_Nair_0-1669934469093.png

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors