web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Sum in joined tables
Power Apps
Answered

Sum in joined tables

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi,

i have hiearchy of 3 tables Orders, Products, Articles. I also have one Table which combines mutliple Products in to orders.

 

In a gallery i have all orders and now i want to have the sum of price in the gallery field.

 

I now need the sum of prices of the articles in a order. I assume forall and groupby could help, but couldnt struggle with it.

 

Holden_0-1678292504004.png

 

How can i i select all products in a order and sum all article prices of it?

 

Thanks & Regards

Categories:
  • Verified answer
    JD382 Profile Picture
    114 on at

    I came up with what I think is a similar data structure to what you have. Here is the code to get the sum. In my example I have a TextInput called "inputOrderNumber." For testing purposes, I just put the code block in a button's OnSelect property.

     

    Set(
     tableArticles, 
     [
     {ArticleID: "art1", Name: "Article1", Price:10},
     {ArticleID: "art2", Name: "Article2", Price: 20},
     {ArticleID: "art3", Name: "Article3", Price: 30}
     ]
    );
    
    Set(
     tableProducts,
     [
     {ProductID: "prod1", Name: "Product1", ArticleID: "art1"},
     {ProductID: "prod2", Name: "Product2", ArticleID: "art2"},
     {ProductID: "prod3", Name: "Product3", ArticleID: "art3"}
     ]
    );
    
    Set(
     tableOrders,
     [
     {OrderID: "order1", OrderNumber: 123},
     {OrderID: "order2", OrderNumber: 456},
     {OrderID: "order3", OrderNumber: 789}
     ]
    );
    
    Set(
     tableProductOrders,
     [
     {OrderID: "order1", ProductID: "prod1"},
     {OrderID: "order1", ProductID: "prod2"},
     {OrderID: "order1", ProductID: "prod3"},
     {OrderID: "order1", ProductID: "prod1"},
     {OrderID: "order2", ProductID: "prod2"},
     {OrderID: "order2", ProductID: "prod3"},
     {OrderID: "order3", ProductID: "prod1"},
     {OrderID: "order3", ProductID: "prod2"},
     {OrderID: "order3", ProductID: "prod3"}
     ]
    );
    
    ClearCollect( //This will serve as the collection of prices in the order so that the sum can be calculated
     collOrderPrices,
     Blank()
    );
    
    ForAll(
     tableProductOrders,
     If(
     OrderID=LookUp(tableOrders, OrderNumber=Value(inputOrderNumber.Text), OrderID),
     Collect(
     collOrderPrices,
     LookUp(
     tableArticles,
     ArticleID=LookUp(tableProducts, ProductID=tableProductOrders[@ProductID], ArticleID),
     Price
     )
     )
     )
    );
    
    Set(
     varOrderTotal,
     Sum(collOrderPrices, Value)
    )
  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi,

     

    thanks for your help. This approach did help me to figure my code out to a working one.

     

    Instead of using a single sum value, i added a 3rd Collections where all the sums in the forall Loop whre saved. I used that collection to gather values from my gallery.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 234 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 207 Most Valuable Professional

#3
timl Profile Picture

timl 122 Super User 2026 Season 2

Last 30 days Overall leaderboard