Calculate weighted usage of an item - google-sheets

I have a Google Sheets workbook with 2 worksheets.
Sheet 1 lists about 1000 items (components). The list could grow.
(ignore E through K columns in the above example)
Sheet 2 lists some products (200 or so at the moment, but the list could grow). Each product could contain up to 12 components. These are listed in columns C through N (all of these columns have data validation so that these need to be selected from Sheet 1's list of 1000 components). Column R contains the number of units of the product.
On sheet 1, next to each component, I want to calculate the number of units of the component used across all products. Of course countif will count only the instances of the particular component in Sheet 1!C2:N200. Similarly sumproduct doesn't fit the bill because 1. C through N are not numerical and 2. C through N are not fixed.
Is there a simple way to calculate the number of units for each component?
(without using VBScript/Javascript, and without copy-pasting the transpose list of components onto Sheet 2)
I am thinking some quirky way of using sumif or sumifs may be the answer here, but haven't figured out yet.

In Sheet1 cell B2. put this formula:
=ARRAYFORMULA(IFERROR(VLOOKUP(A2:A,QUERY(SPLIT(FLATTEN(Sheet2!C2:N&"|"&Sheet2!R2:R),"|",0,0),"select Col1,SUM(Col2) group by Col1"),2,0)))
if you want to return 0s instead of blanks for unused components, this slight modification should do it.
=ARRAYFORMULA(IF(A2:A="",,IFERROR(VLOOKUP(A2:A,QUERY(SPLIT(FLATTEN(Sheet2!C2:N&"|"&Sheet2!R2:R),"|",0,0),"select Col1,SUM(Col2) group by Col1"),2,0),0)))
Demo Sheet

A complementary way is to build a data base
=ARRAYFORMULA(SPLIT(FLATTEN(Sheet2!A2:A&"|"&Sheet2!C2:N&"|"&Sheet2!R2:R),"|",,false))
and then compute via a pivot table, added in
https://docs.google.com/spreadsheets/d/1Lokoms22tuqU53TlhAcdqaldQe_H7Pq8Jah2kBBYo7c/edit#gid=1233865099

Related

Google Sheets function to divide two arrays and return the lowest number

So I manufacture products and the challenge is I need to work out in a Google Sheets spreadsheet how many of each of my recipes (flower bouquets in this case) I can make with the current stock on hand.
I have a dataset which shows my stock qty (number of each flower) in column B, then I have my products across the top of the page in a row. Product 1 is shown in column C, Product 2 in D etc....
Here is the example.
Divide two arrays and return lowest number
As I have hundreds of products and also hundreds of different component parts I need to work out what formula can essentially divide these two arrays and return to me the MIN or lowest number, this is essentially the number of bouquets I can make.
Thanks in advance
I have tried experimenting with SUMPRODUCT as I wondered if you can use this for division as well as multiplication, but I cannot seem to fathom this
Use the following formula in C11:
= ROUNDDOWN(MIN(ARRAYFORMULA(IFERROR( $B2:$B9/C2:C9 ))))
You can then drag the formula to D11.
Alternatively you can use the new bycol function to calculate the complete array:
= BYCOL(ARRAYFORMULA(IFERROR( B2:B9/C2:D9 )), LAMBDA(x, ROUNDDOWN(MIN(x))))

How to use Arrayformula on some of the rows in two ranges

I'm trying to make some protected sheet which will combine data from two others:
Sheet1 - Has mix of entries:
Sheet2 - Has only t1 entries
Sheet3 (protected) - Need ARRAYFORMULA for this sheet to be able to make following:
So in Sheet3 I need to take all t1 entries from Sheet1 and all entries from Sheet2 and list them in Sheet3 ordered by Date.
But so far I could do only ARRAYFORMULA(Sheet1!A2:C5) which copies all entries from Sheet1
This is a job for QUERY formula:
Try this in Sheet3:
=query({Sheet1!A1:C;Sheet2!A1:C},"select * where Col1='t1' order by Col3 asc",1)
Find working example here: https://docs.google.com/spreadsheets/d/1P6uYZcQJqKt7OVPhYtMoDkssfFbhsJVSGACI8u9qMmo/copy
First:
I combine 2 ranges using { } notation
{range1;range2} means that I stack 2 ranges - one on another.
Then using QUERY i select all the Columns in my combined range and order them by third column.
Number 1 at the end of the formula means that range has one row of headers.
=sort({filter(Sheet1!A2:C5,Sheet1!A2:A5="t1");filter(Sheet2!A2:C5,Sheet2!A2:A5="t1")},3,true)
works.
For larger sheets, you should be able to drop the numeral 5 in the above formula.
The {} bracket means local array. ; means vertical concatenation. For sort() and filter(), see official documentation.

Excel Count and Multiply cells between sheets

I have 2 sheets, Sheet 1 and Sheet 2.
In Sheet 1 is a list of Vacancies in one cell and next to it is the Name of the person who has those Vacancies.
In Sheet 2 I am trying to find the TOTAL amount of Vacancies that each person listed has using a Formula
=COUNTIF(Sheet1!B:B,A2)
The only problem is that it needs to count in Sheet 1 how many vacancies a specific person has.
eg: it shows John has 3 vacancies when he should have 11.
Added a SUMIF attempt
The issue is that you should use SUMIF() instead of COUNTIF() as per the comments above, though since you are not using Excel but Google Spreadsheets, this opens up other options (note, the two look alike but are actually very different).
You could try utilize QUERY():
Formula in D1:
=QUERY(A1:B,"Select B, Sum(A) where A is not null group by B label Sum(A) 'Total Vacancies'")

How do I create a multiple sheets that use a google sheet named TOTAL as the data source?

How do I create multiple sheets that use a Google sheet named TOTAL as the data source? Each sheet must contain the same three columns from TOTAL and other specific data, for instance, FLUX will have six columns, three from TOTAL and three custom columns added manually.
I used a query function to import the data from TOTAL to FLUX so that updating data in TOTAL will update it also in FLUX
The data in TOTAL are not fixed. It will change adding rows, which might change the order of the list. For instance, adding the row 13 in TOTAL will shift down the data in column A:C in FLUX, but not columns D:F
Is that a way to keep the reference out of the QUERY part?
Here an example: Click me
you would need to create ID system and then you would be able to match your query with rest of the static columns. in sheet SALES remove that query and put IDs in A column. then your query will be:
=QUERY(TOTAL!A1:D, "SELECT A, B, C, D WHERE C is not null", 1)
where column A contains IDs and then you create new sheet SHEET3 and paste this query in A1
and this formula in E1:
=ARRAYFORMULA(IFERROR(VLOOKUP(A1:A, SALES!A1:G, {4,5,6}, 0), ))
I have the same problem and I can't understand few steps from the answer.
Firstly, the A columns of both sheets (TOTAL and SALES) must have IDs?
Secondly, I can't really understand how the Sheets SALES should look like. Should it be like, Col A = IDs, ColB to C query from TOTAL and Col E to G static data?
In this case is it still correct creating a query in Sheet3 reading data from TOTAL?
Thank

Google Sheets: Script to find duplicates in a column and add their corresponding values from another column

I'm trying to accomplish a lot with little knowledge, but I have a spreedsheet with data that i want to convert into something readable that I can then display on my website.
Anyways, in column A I have a list of dates, column B a list of names, and column c a list of contributions. What I would like to do is first total the amount of contributions in C, for a date range in A.
I would then like to find all the duplicates in Column B(repeat donors), and total their contributions in C.
There is a VBA, that I found on here that would accomplish the second task, but ... I'm using Google Sheets. What I've been doing is sorting the sheet and totalling everything manually.
What I would like to do is first total the amount of contributions in
C, for a date range in A.
Use SUMIF
I would then like to find all the duplicates in Column B(repeat
donors), and total their contributions in C.
Assuming you have 100 records, starting from 1st row for below code.
In cell D1, put =UNIQUE(B1:B10), it will fill D column with unique values of given range (B1:B100).
In cell E1, put =SUMIF(B$1:B$100,D1,C$1:C$100)
Repeat same formula in E column

Resources