How do you get a sum of all the related value...

How do you get a sum of all the related values for a column in a related table?

I have a [SqYd_Calc] table with columns for Length & Width. Then there are

virtual columns for SqFt & SqYd that auto-enter the converted values. These are working fine, and showing these related records In-Line with the Group Aggregate of SUM::SqYd is the exact value I need (77 in the image below).

However, I want to access this value for further calculations ([Price] = rate * SqYd). And although the Group Aggregate feature makes displaying this value very easy, I canโ€™t figure out how to get the same value in the equation editor. I can only get the product of ALL SqYd rows. What formula is the Group Aggregate for SUM::SqYd using?

0 12 3,226
12 REPLIES 12

Iโ€™ve tried several approaches in the equation editor and I either get a sum of ALL rows, or an error that the input is not the expected format. I just canโ€™t get the syntax right to SUM only the related rows.

@Aleksi_Alkio TY Sir! Translate

@GreenFlux I think what you need is another Virtual Column {OrderTotal] with an App Formula something like this, which Totals up my OrderDetails LineTotals for my Order.

=SUM ( SELECT (OrderDetails[LineTotal], [OrderID] = [_THISROW].[OrderID]))

Thanks @Stephen_Mattison ! Should this column be created in the Line Item table, or the Order table? I still canโ€™t get a valid equation with this syntax.

@GreenFlux Order Table, Virtual column, App Formula.

Got it! Thanks @Stephen_Mattison!

=SUM ( SELECT (Line Item[SqYd], [Order] = [_THISROW].[Key]))

@GreenFlux Sweet!

Good work!

Just for the informationโ€ฆ more effective way to calculate this is a formatโ€ฆ SUM(SELECT([SqYd_Calc][SqYd],TRUE)).

With this format you donโ€™t need to search the whole child table again because you have that list already in your hand (in the virtual list column).

SUM(SELECT([SqYd_Calc][SqYd],TRUE))

Canโ€™t this be just SUM([SqYd_Calc][SqYd]) ?

Yes.
Also, things have changed a lot in 2 years, best to take advice in 2 year old threads with a grain of salt.

@Aleksi_Alkio Thanks! This looks much closer to what I attempted yesterday, but I kept getting a syntax error.

I was missing the TRUE at the end. I guess the WHERE parameter is required in the AppSheet implementation of SELECT.

Wellโ€ฆ actually itโ€™s more like a condition check.

Top Labels in this Space