# Weekly Trends - Adding Group Column

**URL:** <https://community.tiller.com/t/weekly-trends-adding-group-column/17582>\
**Category:** Google Sheets\
**Created:** [April 21, 2023, 4:19pm UTC](https://community.tiller.com/t/weekly-trends-adding-group-column/17582 "2023-04-21T16:19:01Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![eliande](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tiller.com/eliande/32/189_2.png) [@eliande](https://community.tiller.com/u/eliande)\
**Post date:** [April 21, 2023, 4:19pm UTC](https://community.tiller.com/t/weekly-trends-adding-group-column/17582/1 "2023-04-21T16:19:01Z")

</div>

Hi there! I just started using the Weekly Trends page from the Community Solutions and I’m wondering how I can add a Group column so that the rows can be sorted by Group (instead of alphabetically by Category Name). I can’t quite figure out how this sheet is structured so my initial attempts to modify it all ended in failure. Anyone have any suggestions on how to approach this?

---

<div class="post-metadata">

**Author:** ![bentyre1](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tiller.com/bentyre1/32/8130_2.png) [@bentyre1](https://community.tiller.com/u/bentyre1)\
**Post date:** [April 21, 2023, 4:42pm UTC](https://community.tiller.com/t/weekly-trends-adding-group-column/17582/2 "2023-04-21T16:42:22Z")

</div>

If you’re talking about having the group populate based on what category you select for the transaction then you can add an additional column in your transactions that contains the following array formula to accomplish this.

> =ARRAYFORMULA(IFERROR(VLOOKUP(D:D,Categories!A:B,2,FALSE),IFERROR(1/0)))

This assumes that your category column is in column D and your group column on the categories page is in column B if those two things are true then this formula will work without modification

As long as row 1 doesnt get moved you should be able to sort as requested

---

<div class="post-metadata">

**Author:** ![eliande](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tiller.com/eliande/32/189_2.png) [@eliande](https://community.tiller.com/u/eliande)\
**Post date:** [April 21, 2023, 4:58pm UTC](https://community.tiller.com/t/weekly-trends-adding-group-column/17582/3 "2023-04-21T16:58:01Z")

</div>

Yup, I can do that in the Transaction sheet! But I when I use the same approach in the Weekly Trends sheet and then sort, all the data disappears. The array formula in the Weekly Trends sheet looks like this:

> =iferror(QUERY(J4:N, “SELECT L, SUM(M) WHERE L \<\> ‘’ AND N \<\> ‘Hide’ GROUP BY L PIVOT J”, 1))

But I don’t know if the QUERY formula will just default to alphabetical order? And thus sorting will completely fail to work every time?

---

<div class="post-metadata">

**Author:** ![eliande](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tiller.com/eliande/32/189_2.png) [@eliande](https://community.tiller.com/u/eliande)\
**Post date:** [April 21, 2023, 4:59pm UTC](https://community.tiller.com/t/weekly-trends-adding-group-column/17582/4 "2023-04-21T16:59:51Z")

</div>

The QUERY is referencing a data table of total spend by category by week, in case that helps.

---

<div class="post-metadata">

**Author:** ![bentyre1](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tiller.com/bentyre1/32/8130_2.png) [@bentyre1](https://community.tiller.com/u/bentyre1)\
**Post date:** [April 21, 2023, 7:00pm UTC](https://community.tiller.com/t/weekly-trends-adding-group-column/17582/5 "2023-04-21T19:00:39Z")

</div>

My apologies, i missed that it was on that sheet instead of just populating them to the transactions sheet, let me mess with that this evening and see, if someone else isnt able to help before then.

---

<div class="post-metadata">

**Author:** ![bentyre1](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tiller.com/bentyre1/32/8130_2.png) [@bentyre1](https://community.tiller.com/u/bentyre1)\
**Post date:** [April 23, 2023, 6:31pm UTC](https://community.tiller.com/t/weekly-trends-adding-group-column/17582/6 "2023-04-23T18:31:38Z")

</div>

This query stuff is a bit beyond my scope, but I was able to figure out that If you just want to change the category view to group view, then in K4 change the regex extract lookups from Category to Group after having the other Array formula in your transactions sheet.

You’ll also want to change K1:K2 to Group as the sparklines reference that

The new formula in K4 will look like

> =QUERY(INDIRECT(“Transactions!A:AE”), “SELECT " & REGEXEXTRACT(ADDRESS(1,MATCH(“Date”, Transactions!A1:AF1, 0)), “[A-Z]+”) & “,” & REGEXEXTRACT(ADDRESS(1,MATCH(“Group”, Transactions!A1:AF1, 0)), “[A-Z]+”) & “, SUM(” & REGEXEXTRACT(ADDRESS(1,MATCH(“Amount”, Transactions!A1:AF1, 0)), “[A-Z]+”) & “) WHERE " & REGEXEXTRACT(ADDRESS(1,MATCH(“Date”, Transactions!A1:AF1, 0)), “[A-Z]+”) & " \>= DATE “”” & TEXT(NOW()-WEEKDAY(NOW(),3) - 28, “YYYY-MM-DD”) & “”” AND " & REGEXEXTRACT(ADDRESS(1,MATCH(“Date”, Transactions!A1:AF1, 0)), “[A-Z]+”) & " \<= DATE “”" & TEXT(NOW() - WEEKDAY(NOW(), 3) + 6, “YYYY-MM-DD”) & “”" GROUP BY " & REGEXEXTRACT(ADDRESS(1,MATCH(“Date”, Transactions!A1:AF1, 0)), “[A-Z]+”) & “,” & REGEXEXTRACT(ADDRESS(1,MATCH(“Group”, Transactions!A1:AF1, 0)), “[A-Z]+”) & " LABEL SUM(" & REGEXEXTRACT(ADDRESS(1,MATCH(“Amount”, Transactions!A1:AF1, 0)), “[A-Z]+”) & “) ‘Total’”, 1)

Another option may be to make the lookup reference Cell K1 so that when changed to Category or Group everything will updated accordingly that part would be MATCH(K1, in both spots in the query formula

If you are looking to have both Group and Category and sort by group, I’m not sure I’ll be able to assist in that endeavor.

To sort in a different order you would need to modify the query that you referenced in C5

---

<div class="post-metadata">

**Author:** ![eliande](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tiller.com/eliande/32/189_2.png) [@eliande](https://community.tiller.com/u/eliande)\
**Post date:** [April 24, 2023, 4:38pm UTC](https://community.tiller.com/t/weekly-trends-adding-group-column/17582/7 "2023-04-24T16:38:57Z")

</div>

I figured it out, with a bit of help from Chat GPT : )

1. Added a Group column to the data table in columns J:N (just adding a new column O and did a Vlookup on Category to find Group)
2. Modified the Query to call both the Category and Group columns (L and O), then included the Group column (O) in the Group By instruction

So the new Query call is:  
`=QUERY(J4:O, "SELECT L, O, SUM(M) WHERE L <> ' ' AND N <> 'Hide' GROUP BY O, L PIVOT J", 1)`

That way I get both Group and Category in the created table, and Group is the driver for how the rows are ordered.

And then, of course, update the reference for the sparkline graphs for the correct columns! : )

---

<div class="post-metadata">

**Author:** ![randy](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tiller.com/randy/32/16_2.png) [@randy](https://community.tiller.com/u/randy)\
**Post date:** [April 24, 2023, 9:08pm UTC](https://community.tiller.com/t/weekly-trends-adding-group-column/17582/8 "2023-04-24T21:08:49Z")

</div>

Well done, @eliande! It’s so satisfying when you pull of something challenging like this. Toast yourself.

🤖

---

<div class="post-metadata">

**Author:** ![eliande](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tiller.com/eliande/32/189_2.png) [@eliande](https://community.tiller.com/u/eliande)\
**Post date:** [April 25, 2023, 3:00am UTC](https://community.tiller.com/t/weekly-trends-adding-group-column/17582/9 "2023-04-25T03:00:01Z")

</div>

Thanks so much for jumping in to help, Ben!! 🙂

---

<div class="post-metadata">

**Author:** ![morgan](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tiller.com/morgan/32/6841_2.png) [@morgan](https://community.tiller.com/u/morgan)\
**Post date:** [April 26, 2023, 4:08pm UTC](https://community.tiller.com/t/weekly-trends-adding-group-column/17582/10 "2023-04-26T16:08:38Z")

</div>

👋, @eliande

Did any of these suggestions help? If so, please mark one as the solution.

 ![mark-solution](https://us1.discourse-cdn.com/flex020/uploads/tillermoney/original/2X/4/4a7422d9d467d37d1071de84fcd5152a437de915.gif)
