Gooogle Sheets - Arrayformula - Gather all text from rows with same key id

This is and indirect app sheet question, regarding google sheets.

I am trying to create an arrayformula in sheets that will look at a related โ€œkey idโ€ column and gather all text from another column from all rows with the same related โ€œkey idโ€:

โ€“ col A / col B / col C

1- KEY ID / NOTE / COMPILED NOTES


2- A1BZ / TACO / TACO FROG

3- T212 / CORN / CORN APPLE

4- T212 / APPLE / CORN APPLE

5- CD41 / DOG / DOG

6- A1BZ / FROG / TACO FROG

(Ignore the fact that rows cannot share a KEY ID, I know this. Itโ€™s just simplified to display the idea).

I am using it as a back end formula and as the sheet is active (having rows removed and added I need this to be an arrayformula. I thought some type of JOIN() with an IF statement. But Iโ€™ve note come up with anything that works. I can make it work if itโ€™s not an array formula with a FILTER(), but the formula doesnโ€™t always auto propagate into new rows.

I understand that there are ways to do this directly in Appsheet, but the issue is in keeping the data โ€œliveโ€ with out having to โ€œupdateโ€ each affected row. Again I understand I could create an action to do this, but the back end sheet solution seemed the simplest.

Any thoughts from the hive mind?

Solved Solved
0 19 2,665
1 ACCEPTED SOLUTION

On a related note the โ€œarrayformulaโ€ for the google sheets side would look like this for my demo example above.

=ArrayFormula({โ€œCOMPILED NOTESโ€; IF(A2:A="",VLOOKUP(A2:A,TRIM(SPLIT(FLATTEN(QUERY(QUERY({A2:A&"~",B2:B},โ€œSelect MAX(Col2) WHERE Col2 Is Not Null GROUP BY Col2 PIVOT Col1โ€),9^9)),"~")),2,FALSE))})

And the fully functional table side of google sheets the final product looks like this:

=ArrayFormula({โ€œCOMPILED NOTESโ€; IF(I2:I="", VLOOKUP(I2:I,TRIM(SPLIT(FLATTEN(QUERY(QUERY({I2:I&"~",N2:N},โ€œSelect MAX(Col2) WHERE Col2 Is Not Null GROUP BY Col2 PIVOT Col1โ€),9^9)),"~")),2,FALSE))})

View solution in original post

19 REPLIES 19

Dont user Spreadsheet formula, but user AppSheet expression to achieve your goal (app).

There are 1000โ€™s of rows and 10โ€™s of โ€œrelated key idโ€™sโ€. I would need a way in the app that anytime a record is added / updated / or deleted, that it searches for all related โ€œrelated key idโ€™sโ€ and updates those entries at the same time. Seems a cumbersome way to go about it when an arrayformula will do the same in less time.

Appsheet is not supporting arrayformula as far as I know.

You are correct, Appsheet doesnโ€™t support arrayformulas. Google sheets does, I uses them across 13 different apps to help do things that Appsheet isnโ€™t very good at.

Appsheet can do the same

My point is donโ€™t lean on spreadsheet formula but use Appsheet expression to achieve your goal

Select(TableName[Col B],[Key ID]=[_ThisRow].[Key ID])

Works great for a single row, but not if I need to update 10 or 20 rows that have the same data.

This would work as a virtual column. So everytime to add or update [Col B] then [Col C] will recalculate.

I will give the virtual column a shot.

Disclaimer, I donโ€™t really recommend doing this, but if you must knowโ€ฆ

FILTER and QUERY donโ€™t really work inside arrayformula. VLOOKUP does though, but only returns a single value, so youโ€™ll need 1 formula per column.

ARRAYFORMULA( IF( key-cell-range <> "" , VLOOKUP(...) , "" ) )

Load the table into the app without the formula, then put the formula in afterwards so Appsheet doesnโ€™t even know about it.

Thanks for the assistance. I have used many backend formulas (and arrayformulas) before and they work great with appsheet. The array vlookup will not work due to the single value return.

Right, so whatโ€™s wrong with my suggestion

?

Seems like I will need to create an action that searchโ€™s all data entries with โ€œrelated key idโ€™sโ€ and update them as well.

You could evaluate AppSheetโ€™s Webhhok API option to collate the text based on changes in [Note] column. Testing over 4 /5 records collation shows that the update is fairly quick. But if the change traffic of records changing or getting added is high, it may not be practical and even not advisable either way - with actions or webhook

The example below shows when the [Quantity] is added through โ€œOrder Detailsโ€ in an order, the Webhook runs to update all the records for that order ID with cumulative quantities for all the order detail records. ( In the example the order ID is โ€œ304C5A83โ€ and quantities of 5 and 10 were added through different order details that were collated in the [ProductQuantity] column.

I will give this a look, seems pretty promising.

On a related note the โ€œarrayformulaโ€ for the google sheets side would look like this for my demo example above.

=ArrayFormula({โ€œCOMPILED NOTESโ€; IF(A2:A="",VLOOKUP(A2:A,TRIM(SPLIT(FLATTEN(QUERY(QUERY({A2:A&"~",B2:B},โ€œSelect MAX(Col2) WHERE Col2 Is Not Null GROUP BY Col2 PIVOT Col1โ€),9^9)),"~")),2,FALSE))})

And the fully functional table side of google sheets the final product looks like this:

=ArrayFormula({โ€œCOMPILED NOTESโ€; IF(I2:I="", VLOOKUP(I2:I,TRIM(SPLIT(FLATTEN(QUERY(QUERY({I2:I&"~",N2:N},โ€œSelect MAX(Col2) WHERE Col2 Is Not Null GROUP BY Col2 PIVOT Col1โ€),9^9)),"~")),2,FALSE))})

Thank you very much for sharing the array formula and solution. The formula is indeed impressive and extensive.

Just so that we understand the requirement better for any future use, may we request you if possible to share the approximate volume of record changes in a single day (Adds of new records plus edits of the [Note] column that needs collation).

You question is not an easy one to answer. In short anywhere from 1 to 1000 additions, changes or deletes in a day. I am happy to provide more details for you & the team to help you understand.

It is part of a rather complicated / interlinked, Tracking number generator, Calendar, and timesheet system (and other apps). This formula is being used in the Calendar system (table based not google calendar). Which in itself (on the surface) may only have 10 to 50 additions / changes / deletes per day to the Calendar.

Hereโ€™s a very very basic breakdown of the system (I will try to be concise).

Tracking numbers (New entries per day 1 - 200) This is the systems core, everything uses this.

  • You input the job data and it creates a sequential number
  • You can bundle multiple tracking numbers under a master tracking number (important later on)
    ~RELATED / SUPPORT SYSTEM TABLES~
    - Customer - Customer data
    - Customer assets - Customer equipment data
    - Corrective log - Technicians log equipment errors, tied back to the jobs Tracking number
    - Estimate Log - An estimate bundle (with a new related estimate tracking number) for each
    corrective batch
  • Existing corrective & estimate key idโ€™s can be turned in to new job tracking numbers. a corrective key id (or a full batch of correctives, multiple key idโ€™s) can get a new tracking number and become estimates. Alternately individual estimate or corrective key idโ€™s can be โ€œflippedโ€ into tracking numbers to become jobs. For example 20 corrective items (20 key ids) can become a single tracking number which gets estimated and sent. Of those 20 estimate items a customer can approve any combination of all or some of the items. Each approved key id can then be flipped and become a new job tracking number. Say they approve 17 items, there would then be 17 new tracking numbers, but there would also be a 18th MASTER number (used to issue a united invoice). all 18 numbers are interlinked in the system (again this is important later).

Time Log (New entries 10 - 100 per day)

  • Allows the tech to fill out a timesheet for the tracking number or numbers they were assigned
    • Part of this data is identifying if the job has been completed.

Calendar (New entries 10 - 50 per day)

  • Table based, not at all driven by google calendar.
  • The Calendar is split in 2 apps, a management and scheduling side, and a read only technician display. This has been done to keep the data low and the speed of the mobile technician calendar as fast as possible.
  • Allows management to pull up Tracking numbers and all of the related data (Customer, correctives, estimates) and populate the calendar event with the related data (Notes, asset data, corrective, or estimate repair information, parts purchases and so on).
  • In the case of individual assignment, single day & stand alone tracking number projects, when a job is complete we do not need to have any concern of work being duplicated.
  • In the case of Master tracking numbers, which typically involve multiple technicians over the span of multiple days. Using the example of the 17 approved jobs under 1 master number above, We create a new calendar entry using the master number. We hide the master tracking number and the technicians on site read the notes section to see what tasks need to be completed and what the child tracking number for that task is. The technician notes the tracking number as being completed when using the time log app. The Calendar notes, that detail the list of the 17 tracking numbers, automatically updates and removes the data for the completed job from that master list (the notes in the calendar). Keep in mind, a master tracking number job that has 17 parts, might have 3 technicians working on it for a week (maybe more). Thatโ€™s 15 or more daily calendar entries to keep current notes / statuses on (255 total notes).

The system is rather large (12 apps working together as one). The technician Calendar app references only the Calendar table as read only to keep the speeds up. So the data cannot be referenced via Virtual Columns on the technician app. It can be referenced in the managers calendar app, but then needs to be written to a physical column so it will appear in the technician app. As soon as you write data in Appsheet you need to update each individual instance of the data to update if the virtual data changes so it writes correctly so the technician calendar displays correctly. I know there are ways to do this but they all involve someone doing something in the app. The google sheet side arrayformula takes care of this with out the need to update anything. We then always know that the calendar data across all of the technicians calendar entries is up to date.

I use many google sheet side arrayformulas across all of the apps to facilitate automatic updates like the calendar note update. For example the Correctives table has one that looks at the Estimates and the Time Logs to see if estimates have been created or if the corrective has been done (estimates has a similar formula to see if a project has been completed). I also use an arrayformula to create (problem free) sequential tracking numbers, as Key IDโ€™s are confusing for our technicians. Key IDโ€™s are still there, the technicians just donโ€™t use them to communicate. Itโ€™s simple to say that you are working on Job 3520, and search that number over the entire system, or remember it to enter it into your time log, rather than 6029e56b.

I hope I have given enough detail, but not too much to be confusing.

Hi @Tom_Stevens ,

Thank you very much for such a detailed explanation. My question was of course just to know the volume of updates to your original requirement so the future reader of the post and us could probably understand when it makes sense to use say actions/ webhook options versus arrayformulas option.

Your operation seems substantial for calendar (10-50 entries per day). I was wondering if webhook option would also have helped in this case. But you seem to need instant updates in many places, in many apps, so arrayformulas make sense.

Thank you again very much. Appreciate.