Finding the SUM of a list of numbers inside a bullet list

Hi all,

I’ve been scratching my head on this one, my needs are quite simple, all I need to do is show a SUM of prices that are listed in a repeater bullet list, no matter what I try I just cant get it to show a SUM total. The repeat region data is taken from a db join that pulls the ‘PricingPrice’ data from an array inside a bookings table.

Heres what I have so far

<ul>
                                                <li dmx-repeat:repeat1="scServicesList.data.queryServices" dmx-show="dataBookingDetails.data.BookingServicesRequired.contains(PricingID)">
                                                    £{{PricingPrice.toNumber()}} {{PricingTitle}}
                                                </li>

                                                sum = {{PricingPrice.sum()}}


                                            </ul>

Front end is here:
image

Can anybody put me out of my misery…? :slight_smile:

I believe you have to convert your sum to a number as well.

You can’t sum it like that. You need to apply the sum formatter to the query scServicesList.data.queryServices

I’m not sure I can do that for this query, I have two tables ‘bookings’ and ‘valetpricelist’ the valetpricelist.PricingID is taken from an array in the bookings table in the column BookingServicesRequired (example: 71,77,92) then iterated through the bullet list using the scServicesList.data.queryServices as the filter.

the scServicesList.data.queryServices query only contains the aggregate of the list of all prices, and not the ones selected by the dmx-show in the bullet list.

OK, I tried this:

then updated the sum= bit to
sum = {{scServicesList.data.queryServices[0].SumTotal}}

It returned the following:
image

I’m getting close, I can almost smell the victory, I’ll keep plugging away but if any of you can see a glaring omission please let me know…

I really appreciate this forum, I’ve spent so much time reading it I feel like I know everyone without even knowing what anyone looks like :slight_smile:

Try

{{scServicesList.data.queryServices.sum('PricingPrice')}}
1 Like

What if you take out the [0] … you are only getting the sum of the first element.

@bpj that gives a sum of sum = 587 which I guess is the total of all of the options and not the ones shown in the repeated bullet list…

@brad that gives a blank record

How about this, you create an App Connect variable called “servicesSum”

And then, on server connect scServicesList success, you run an App Flow, and inside it you have a Repeat to iterate scServicesList.data.queryServices, and for each value you increment servicesSum.value (make sure to convert the current price to a Number, as it’s probably a string by default)

And then in the HTML you just put an App Connect Binding for the variable servicesSum, like this:

{{ servicesSum.value }}
1 Like

I didn’t spot that you were hiding/showing some based on a data store.

Try:

{{scServicesList.data.queryServices.where('PricingID', dataBookingDetails.data.BookingServicesRequired,'inArray').sum('PricingPrice')}}
3 Likes

BINGO…!!!

You, my friend, are a genius - there’s no way at all I’d have gotten that one. Thank you so much for your help, its greatly appreciated. Hopefully I’ll be able to pay some Karma forward by helping others whenever I can.

Thank you also to all other contributors, you all provided some excellent answers which will definitely help in the future. @Apple your flow suggestion is stored in my memory bank for future usage :slight_smile:

2 Likes