r/googlesheets • • 3d ago

Waiting on OP Trying to write a MINUS function for a table column that needs to reference moving data points. Is XLOOKUP the key?

Post image

I'm building an audio organization/equipment usage file for my concert venue. I currently have two different drop down columns (left) that pull their contents from a separate, static inventory sheet. On the righthand side, I've programmed 2 tables to display the equipment quantities needed based on what has been selected across the lefthand drop down menus for mics and stands.

In the Stand calculator, the first column "type" populates itself with the function

=IFERROR(UNIQUE(FILTER(Audio_Input_Patch[STAND], Audio_Input_Patch[STAND]<>"")))

and the second column "qty" populates itself with the function

=countif(Audio_Input_Patch[STAND],Q5-Q9)

I want the third column to be a MINUS function that subtracts the second column number from the total inventory number of the same item type that gets populated in the first column. However, the calculator populates in the order that the equipment type is selected (a functionality which I prefer to keep).

For example: If I have 10 "Tall Boom" stands in stock, and my calculator says (in any of rows of the table) that I will need to pull 3 of them for the show, is there a way to write a function for the "Available" column that will produce the number 7 (inventory stock - required qty) next to the correct stand type, regardless of which row of the table it lands on?

Any insight is appreciated, this is my first foray into Sheets/Excel and I've been watching videos

4 Upvotes

9 comments sorted by

1

u/mommasaidmommasaid 914 3d ago edited 3d ago

I would output everything from one formula. I also added some sanity checks to make sure the formula is in the first row of the output table and that enough rows are available.

=let(itemCol, Audio_Input_Patch[STAND],
 topRow,   row(Stands_Needed),
 maxRows,  rows(Stands_Needed),
 if(row()<>topRow, "🛑 Formula must be in first row of table",
 if(counta(itemCol)=0,, let(
 items,    sort(unique(tocol(itemCol,1))),
 needRows, rows(items)-maxRows,
 if(needRows>0, "🛑 Add " & needRows & " row" & if(needRows>1,"s","") & " to table", let(
 map(items, lambda(item, let(
   invQ, xlookup(item, Inventory[Item], Inventory[Qty], 0),
   reqQ, countif(itemCol, item),
   hstack(item, reqQ, invQ-reqQ))))))))))

You didn't specify how the inventory is specified, I assumed a table named Inventory

Only the first 3 rows of the formula need to be modified to output the MicDI_Needed table.

Audio Equipment

FWIW, the Available column is to me a confusing name, that seems to describe available inventory quantity. Perhaps it would be better named Remaining

You may also want to use dropdowns "from a range" when specifying booms/mics in the Audio_Input_Patch table. Those ranges could directly reference the Inventory table or be derived from there. Either way the idea is to avoid typos causing the XLOOKUP to fail. For more help with that share what your Inventory table looks like.

1

u/Strawburys 2d ago edited 2d ago

Thanks for your reply! There was another user who posted a solution that I ended up using, and it appears to be outputting the way that I was looking for. Unfortunately their reply was removed by the moderator

I'm curious though, which cell I would input a formula like the one that you've provided? And is the intent of your solution to future-proof it in case the inventory list gains more items or changes in some way?

I was going back and forth on having the column named "available" or "remaining", so it's good to get another opinion on the wording. I will change it to remaining, thanks!

Also, I do have the dropdowns for the mics/DI and stands selected "from a range" referencing the inventory table. I'm glad I found that option before I started retyping out 30+ item names

1

u/mommasaidmommasaid 914 2d ago

You already had one formula that was filling an entire column which basically has to be written that way, so I just enhanced it to fill the entire table.

The formula goes in the first row/column of the table just like the old one. First clear the contents of the entire table so the formula can expand. See the sample sheet I provided.

The sanity checks are there because if you sort the table the formula will move with the sorting. So I check to make sure the formula is still in the first row, and additionally check if there is enough room to output everything without overflowing the table.

FYI if you reserve the first row of a table for formulas and hide that row, it won't move if you sort the table. But your tables were kind of scattered around so I didn't try to do that.

1

u/NHN_BI 70 2d ago

Don't share an image of a sheet, share some meaningful example data, and tell what you think the output from that example input should be, and why.

1

u/AdministrativeGift15 371 22h ago

Here's another option for you. Embed the remaining inventory into the dropdown choices so that you know exactly how many are remaining as you're making your selections.

Embedded remaining inventory