I would like to sum a quantity over a running 12 month period

I have a simple spreadsheet that i record my fuel usage on, the last column totals the fuel quantity over a running 12 month period. If uses SUMIFS in Google sheets, but this formula gets overwritten as blank when using my app.
Iโ€™m not sure how to write an expression to do this simple task in AppSheet.
Advice much appreciated

0 14 504
14 REPLIES 14

Sum across the last 12 months prior to the current recordโ€™s [Date]:

SUM( SELECT(
  Table[Veg Oil Qty] ,
  [Date] >= EOMONTH( [_THISROW].[Date] , -13) + 1
) )

Hi, thanks, it says โ€˜Canโ€™t find Tableโ€™
If i assume that is a variable that needs changing to my sheet name it still doesnโ€™t work (โ€˜Sheet1โ€™). Have i misunderstood?

Yes you need to change โ€œTableโ€ to the name of your Table in the app (which could be the same as the Sheet name).

What syntax error am i making here?

What is the name of your Table inside of the app?

Aha, thank you.
That appears to be working, strangely it has now changed the appearance on entries in the app, the โ€˜titleโ€™ of each entry is now that running total instead of the date as before

(iโ€™m not sure why the creator view of the app only shows one entry, the app on my phone correctly shows all 3 entries, but the title issue remains)

Hi Marc, i notice that the running total shown in any given row pertains to the quantity figures up to the previous row.
As shown here, the first three rows still have my original formula in the cells, whereas the fourth entry is the only one after i implemented your expression.

Is there a way for the app to live calculate that total for the number just entered and show it in the total box (and thus enter it into the appropriate cell in the source?

You mean the sum just isnโ€™t including the current record?

yes

I believe the problem is that the expression is running when you are creating the new record. In such a case, the new record doesnโ€™t yet exists in the Table, so the SELECT expression doesnโ€™t pick it up.

You could add a term to the expression:

+
[Veg Oil Qty]

โ€ฆin order to add the current recordโ€™s value to the previous SUM. The problem with this is if you ever edit that record again, the SUM will then be greater than it should be by that recordโ€™s amount. Will you ever be editing the record later?

Thanks Marc, i will give this a test. No, realistically i will not need to edit a record later, once the oil has gone in the tank and been burnt thereโ€™s no going back (unless iโ€™ve made a mistake!)

Thanks again, this works a treat

Iโ€™ll give it a shot. I think that this is very close to what you want:

3X_d_3_d39ad50b58e6a0d0b45cfcaab39fc555e239b198.png

Several things I did differently:

  1. The SUM(SELECT()) statement only defined the start date, not the end date. I changed it. See it below.
  2. For debugging purposes I added two virtual columns, โ€œStartโ€ and โ€œEndโ€, to help to understand the period used by the SUM(SELECT()). Please note that I researched โ€œ12-month rolling periodโ€. I could not find a satisfactory definition, so I took the liberty of defining it my way. Change it to match your requirements.
  3. I did NOT include the formula in the spreadsheet, only in AppSheet as a virtual column.

Here is how I defined the columns:

Start: EOMONTH( [_THISROW].[Date] , -13) + 1
End: [_THISROW].[Date]

Total:
SUM( SELECT(
Table[Veg Oil Qty] ,
AND(([Date] >= EOMONTH( [_THISROW].[Date] , -13) + 1), ([Date] <= [_THISROW].[Date]))
) )

Hope this helps.

Brian

Thankyou for this.
Now that iโ€™m aware of expressions in AppSheet i do not require the formula in the spreadsheet anyway

Top Labels in this Space