Calculations Dependent On Multiple Drop-down Selections - google-sheets

I have the following spreadsheet calculating my household outgoings with a number of categories to choose from multiple drop-down lists (Cols B, C).
In Column H, with the header Outgoings, I would like to sum the columns D and E in two rows based on the selections made in the drop-down lists in J2, J3 which act as filters for said calculation. These drop-down lists reflect the Bill Type in Column B, and the Category in Column C.
As an example, if I selected from the drop-downs in Column J: Personal, Credit/Debit then I would like the two rows in Column H (Outgoings) to be populated with the total sum of the rows D and E, respectively, for where the Bill Type and Category in B and C match Personal and Credit/Debit.
Along with the above conditions, if there is no selection in either of the Column J drop-downs, I would like the rows in Column H (Outgoings) to simply provide the calculation of the incomes in D, E (Row 2) minus the remaining sum of each column (total outgoings, i.e. D2:D).
I'm a little new with the syntax required to perform more complex calculations and was wondering if this was achievable in spreadsheets, specifically, in Google Sheets.

Try this in cell H2:
=if(J2&J3="",
sum(filter(D:D,C:C="Income"))-sum(filter(D:D,C:C<>"Income")),
sum(filter(D:D,B:B=J2))+sum(filter(D:D,C:C=J3))
)
This in H3:
=if(J2&J3="",
sum(filter(E:E,C:C="Income"))-sum(filter(E:E,C:C<>"Income")),
sum(filter(E:E,B:B=J2))+sum(filter(E:E,C:C=J3))
)

Related

Add\remove row based on value

I got a table_1 that has 2 columns in (Q and R) the end with checkboxes.
I want to create and secondary table_2 that has dependency on the table_1 in such a way that it imports rows from Table_1 when I have TRUE value in column Q but removes it when I set value to TRUE in column R.
I tried using Filter, but it does not work after I alter data in table_1.
Basically, I want to make it work all the time. Not just once.
https://docs.google.com/spreadsheets/d/1I9RwXYBeibhL-mQBsSZHbB5QEBD24gbUBWldBucNmsw/edit?usp=sharing
You should use FILTER formula or QUERY formula.
Let's say you want to have a Sheet2 based on Sheet1 where you show only orders paid (P) but not delivered (Q) yet:
Source sheet according to your link:
Solution:
=FILTER(Sheet1!B2:R;Sheet1!P2:P=TRUE;Sheet1!Q2:Q=False)
First parameter: Sheet1!B2:R tells what will be displayed (all rows from 2 to the end and columns from B to R)
Second and Third parameters set conditions that are checked for each row separately.
If you want to have tick boxes in Sheet2, you should select P and Q columns and use Menu --> Insert --> Tick box.
It will change format of these columns but will not affect the content.

Calculate weighted usage of an item

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

In Google sheets, How to do Vlookup unique data from multiple column

My Vlookup formula is the following currently:
(Weekly Consolidated Sheet)
Column C:1
=iferror(arrayformula(if(D:D="Item No.","Document No.",('For NAV'!C3:C))),"")
Column D:1
=iferror(arrayformula(if(A:A="Posting Date","Item No.",Unique('For NAV'!D2:D))),"")
Column I:1
=iferror(arrayformula(if(A:A="Posting Date","Quantity",sumif('For NAV'!D:D,D:D,'For NAV'!I:I))),"")
I would want to consolidate data from "For NAV" sheet into "Weekly Consolidated" Sheet.
"For NAV" Sheet has duplicate Item No. which I want to make it Unique and Sum the total Quantity (Column I)
Now that the document number seems to be the main Criteria I am stuck.
The following is what I need:
Main Criteria = Document No
Example:
ADW 01-07/03
-Item number which has same document number should consolidate its own Unique item number and sum the Quantity
ADW 08-14/03
-Item number which has same document number should consolidate its own Unique item number and sum the Quantity
Other columns is OK i can vlookup from "Item Listing" Sheet based on the Item code
Link for the spreadsheet as below:
https://docs.google.com/spreadsheets/d/1SL63pIF35skZjjbFjTRgfsbSYHvDr-gRRKciZbYFRUU/edit#gid=1168278681
Try changing your formula in I2 to
=ArrayFormula(iferror({"Quantity";sumif('For NAV'!C3:C&'For NAV'!D3:D,C2:C&D2:D,'For NAV'!I3:I)}))
The way this works is by making a unique string generated from the values on the C and D columns to compare between sheets. In this case you can simply joining them together because the the C column is always the same size.

Populate a new Google Sheets sheet, with a random sample, with at least X samples of a given attribute

I have a data set which I would like to take a random sample from and place in to a new sheet. I have one extra constraint / stratification: I would like X examples of each of a given attribute.
For example, if COL A has 5 rows of Apples, 5 rows of Bananas etc., I would like a random sample which includes 2 Apple rows, 2 Banana rows and so on for as many values of COL A as there are.
I am halfway there having got a formula to populate a new sheet with a random sample:
A1: =ArrayFormula(FILTER( SORT('My list of 100000 rows'!A:A ;RANDBETWEEN( 0+ROW('My list of 100000 rows'!A:A) ; ROWS('My list of 100000 rows'!A:A)); TRUE); ROW('My list of 100000 rows'!A:A)<=100))
but this doesn't give me the ability to select a minimum or exact number of instances of each unique attribute.
Any advice is appreciated!
I would like a random sample which includes 2 Apple rows, 2 Banana rows and so on for as many values of COL A as there are.
Insert two columns to the left of your data and in A1:
=choose(randbetween(1,10),"12","13","14","15","23","24","25","34","35","45")
in B1 and copied down to suit:
=countif(C$1:C1,C1)
then :
=query(A:D,"select C,D where B contains '"&left(A1)&"' or B contains '"&right(A1)&"' ")

Filter one sheet, A, with another, B, to get a new sheet, C, with rows that don't exist in B

I'm trying to get rid of bad data in my inventory list.
Sheet A is a sheet that is a list of all my products.
Sheet B is a sheet, generated from another piece of software, that lists all of my products that have been sold
I need to generate a third sheet, Sheet C, that lists all the unsold products. So, the number of rows between Sheet B and Sheet C should add up to the total number of rows on Sheet A.
How do I cross-reference/filter Sheet A with B to achieve C?
The following formula returns the list of entries from column A of Sheet1 that are not present in column A of Sheet2:
=filter(Sheet1!A2:A, isna(match(Sheet1!A2:A, Sheet2!A2:A, 0)))
Explanation: match returns error code #N/A for those entries in Sheet1!A2:A that are not found in Sheet2!A2:A. The isna function converts those to True boolean values. Finally, filter returns those rows for which the second argument evaluates to True.
The filter can return more than one column: it can be, for example,
=filter(Sheet1!A2:Z, isna(match(Sheet1!A2:A, Sheet2!A2:A, 0)))
But match requires a one-dimensional range, so you need a column (here assumed to be A) which can be used as an identifier of a row.

Resources