Match 3 cells pair with other 3 cells pair. Google Sheets - google-sheets

I'm using Google Sheets for our production price calculation and we are getting new orders with different data every week.
I have all the price calculations sorted out but sometimes there are the same data in orders that already been in the past and I have to manually search for it and use the same price if it exists.
As you can see in the example above, when I enter in the selected cell data "100", I have to check if it already exists in cells above (all three cell in the same row) and if it does enter its price on the cell on the right("=" sign), if it doesn't it could say "new" or be left empty.
I looked at the INDEX and MATCH functions but they don't seem to do the trick.
Do you have any suggestions? Of course the formula should be easily copied to every next cell down when new data and orders come in.

Approach
In this case it's useful to have an index for your table. I created a simple one that concatenates the 3 values you have with the & operator. You can see in the table below for the complete formula. Just drag it down to the whole table to make it automatic.
For the price calculation then I am using a VLOOKUP. It will search for the index generated by the three values in the new row and get the corresponding Price if ti exists. If not, it will print NEW. That's just a placeholder of course, you can edit it as you want. I put the first cell of your table as absolute reference in the VLOOKUP formula so you can drag it down and it will always get its upper (already filled) portion.
Table
INDEX X Y Z Price
11010030 110 100 30 1
500300100 500 300 100 2.3
12030010 120 300 10 1.2
500300100 500 300 100 2.3
12030010 120 300 10 1.2
11010030 110 100 30 1
3004510 300 45 10 NEW
11010030 110 100 30 1
=B10&C10&D10 =IFERROR(VLOOKUP(A10, $A$2:I9,5,0), "NEW")

Based on the correct initial thought by Alessandro, please use the following single arrayformula in cell E2
=ArrayFormula(IF(LEN(A2:A)>0,
IF(LEN(D2:D)>0,
VLOOKUP(A2:A&B2:B&C2:C, {A2:A&B2:B&C2:C,D2:D},2,0),"new"),""))
The formula works as a helper column, only showing you what price to use in column D (if it previously exists) or lets you know that you need to calculate a new one.
Functions used:
VLOOKUP
ArrayFormula
LEN
IF

Related

Count amount of cells within a specific year

What I want is for a single column (C-L respectively) to count exactly how many cells in their respective row match the same year (from P onward) as the labeled column. So L5(red) will count how many cells from P5-Z5 have "2022" and K8(pink) will count how many cells from P8-Z8 have "2021" in them.
I currently have the number manually entered into each cell, but would like to automate it so it will count the years on its own. Every string of formulas I have tried all come up as error. It was easier to get a second page to count the amount of cells that have a specific word. But now I can't get a single page to count how many cells contain the specific year date in it on its own page.
Here are various logic formulas I've tried. Each of them just comes up as error.
=COUNTIFS(!P5:cc5,(2022))
=COUNTIFS(!p5:cc5,"&2022")
=COUNTIFS(!p5:cc5,\<="2022")
=COUNTIFS(!p5:cc5,"\<=01/01/2022")
=COUNTIFS(!p5:cc5,"\>=01/01/2022",!p5:cc5,"\<01/01/2023")
=COUNTIF(!P5:cc,YEAR(2022))
=COUNTIFS(!P5:cc,"\<="&DATE(2022))
=(COUNTIF(!p5:cc,"\>="01/01/2022)-COUNTIF(!$p$5:$cc,"\>="01/01/2022))
This one is the formula I have for reading the second page to count how many times the specific name shows up. O5 is the cell with the name in it. So I was basing my year counting off this and trying to google my way through it.
=(COUNTIF('Queue List'!$B$3:$D$400,O5))
Sheet layout
As far as I understand you have 10 columns (C-L) that will have to find how many dates in P:CC are in year 2013,2014,2015... right? You can do it like with this formula in C5:
=COUNTIF(ARRAYFORMULA(YEAR($P5:$CC5)),2010+COLUMN())
You're "scanning" the year of the whole row with arrayformula, and then seeing if it matches 2022. In this case I changed 2022 with 2012+COLUMN() so you can drag it or copy and paste to the whole column and the number of column added to 2012 will "calculate" the corresponding year of each column
Another option is to create a whole array with one single formula in C5:
=MAKEARRAY(ROWS(P5:P),10,LAMBDA(r,c,IF(COUNTA(INDEX(P5:CC,r))=0,"",COUNTIF(ARRAYFORMULA(YEAR(INDEX(P5:CC,r))),2012+c))))
Obviously you can adapt it to a specific range. Right now it creates a "rectangle" of 10 columns wide (C-L) and to the bottom of the page (counting the rows between P5 to P (the end of the sheet). "r" and "c" are the number of the row and the column of each cell being calculated (C5 is Row 1, Column 1. D7 is Row 2, Column 3, etc). With INDEX you can select the row to count from the whole range (using that "r" that equals the row), and with c I use the same logic that with the other formula in order to add to 2012+1 in C, 2012+2 in D, 2012+3 in E, etc.
And COUNTA checks first if there is any value in that row, if it doesn't it leaves that row empty (so you won't have a bunch of unnecesary "0"

How to apply array formula taking data from another table?

We have two tables in Google Sheets.
First:
Date
Amount
Currency
Worth
01.01.2021
100
USD
373
02.01.2021
100
EUR
451
03.01.2021
100
PLN
100
04.01.2021
100
USD
373
05.01.2021
100
USD
372
Second:
Date
PLN
EUR
USD
01.01.2021
1
4,50
3,73
02.01.2021
1
4,51
3,75
03.01.2021
1
4,50
3,74
04.01.2021
1
4,48
3,73
05.01.2021
1
4,49
3,72
I tried find array formula for first table, column Worth. Formula should take proper value from second table (based on two columns from table one - Date and Currency) and multiply that values by worth in column Amount. I really want to use array formula. Is it possible?
Use VLOOKUP to find the correct date row and MATCH to find which column the value is in:
=ARRAYFORMULA(IFERROR(VLOOKUP(A2:A,I2:L,MATCH(C2:C,I1:L1,0))*B2:B))
Option 01: Getting the result with one cell one formula.
Paste this in B3 "Amount" column in the first table, take a look at this Sheet.
=ArrayFormula(IF(ArrayFormula(IF(A3:A="",,VLOOKUP(A3:A,G3:J,ArrayFormula(IF(D3:D="",,MATCH(D3:D,$H$2:$J$2,0)+1)),0)))="",,ArrayFormula(IF(A3:A="",,VLOOKUP(A3:A,G3:J,ArrayFormula(IF(D3:D="",,MATCH(D3:D,$H$2:$J$2,0)+1)),0)))*E3:E))
Explanation ...
1 - MATCH(D3:D,$H$2:$J$2,0) To get the index you want to VLOOKUP the "Currency" column from the second table with, we need that in the next step.
2 - VLOOKUP the "date" found in First table A3:A from Range in the second table G3:J, with Index set to MATCH(D3:D,$H$2:$J$2,0), and [is_sorted] set to 0
3 - till now we have the value of the exchange rate if we can call it that for each Currency chosen in the first Table, we need to multiply it by Worth to get Amount
ArrayFormula(IF(A3:A="",,VLOOKUP(A3:A,G3:J,ArrayFormula(IF(D3:D="",,MATCH(D3:D,$H$2:$J$2,0)+1)),0)))*E3:E is structured like this Exchange rate * Amount note that E3:E is the Amount, and this IF(A3:A="",, to calculate only when A3:A range is not blank.
4 - ArrayFormula and a IF is needed to be wrapped around like this ArrayFormula(IF(Range=Empty,Do nothing,formula)
Range:
ArrayFormula(IF(A3:A="",,VLOOKUP(A3:A,G3:J,ArrayFormula(IF(D3:D="",,MATCH(D3:D,$H$2:$J$2,0)+1)),0)))
Empty
""
Do nothing :
,,
Formula:
ArrayFormula(IF(A3:A="",,VLOOKUP(A3:A,G3:J,ArrayFormula(IF(D3:D="",,MATCH(D3:D,$H$2:$J$2,0)+1)),0)))*E3:E
Option 02: Getting the result with intermediate steps.
Same as option 01 but in seprate columns take a look at this Sheet.

Google Sheet: formula to loop through a range

It's not hard to do this with custom function, but I'm wondering if there is a way to do it using a formula. Because datas won't automatically update when using custom function.
So I have a course list sheet, each with a price. And I'm using google form to let users choose what courses they will take. Users are allowed to take multiple courses, so how many they will take is unknown.
Now in the response sheet, I have datas like
Order ID
User ID
Courses
Total
1001
38
courseA, courseC
What formula to put here?
1002
44
courseB, courseC, courseD
What formula to put here?
1003
55
courseE
What formula to put here?
and the course sheet is like
course
Price
A
23
B
33
C
44
D
23
E
55
I want to output the total for each order and am looking at using FILTER to do this. Firstly I can get a range of unknown length for the chosen courses
=SPLIT(courses, ",") // having named the Courses column as "courses"
Now I need to filter this range against the course sheet? not quite sure how to do it or even if it is possible. Any hint is appreicated.
try:
=ARRAYFORMULA(IF(A2:A="",,MMULT(IFERROR(
VLOOKUP(SPLIT(C2:C, ", "), {F1&F2:F, G2:G}, 2, 0))*1,
ROW(INDIRECT("1:"&COLUMNS(SPLIT(C2:C, ", "))))^0)))
demo spreadsheet
As I need time to digest #player0's answer, I am doing this in a more intuitive way.
I create 2 sheets to store intermediate values.
The first one is named "chosen_courses"
Order ID
User ID
1001
=IFERROR(ARRAYFORMULA(TRIM(SPLIT(index(courses,Row(),1),","))),"")
1002
=IFERROR(ARRAYFORMULA(TRIM(SPLIT(index(courses,Row(),1),","))),"")
1003
=IFERROR(ARRAYFORMULA(TRIM(SPLIT(index(courses,Row(),1),","))),"")
In this sheet every row is a horizontal list of the chosen courses, and I created another sheet
total
course price
=IF(isblank(order_id),"",SUM(B2:2))
=IFERROR(VLOOKUP('chosen_courses'!B2,{course_Names,course_price},2,false),"")
=IF(isblank(order_id),"",SUM(C2:2))
=IFERROR(VLOOKUP('chosen_courses'!B2,{course_Names,course_price},2,false),"")
=IF(isblank(order_id),"",SUM(D2:2))
=IFERROR(VLOOKUP('chosen_courses'!B2,{course_Names,course_price},2,false),"")
course_Names,order_id and course_price are named ranges.
This works well, at least for now.
But there is a problem:
I have 20 courses, so in the 2nd sheed, there are 21 columns. And I copy the formulas to 1000 rows because that is the maximum rows you can get to using ctrl+shift+↓ and ctrl+D. Now sometimes when I open the sheet, there will be a progress bar calculating formulas in this sheet, which could take around 2 mins, even though I have only like 5 testing orders in the sheet. I am afraid this will get worse when I have more datas or when it is open by old computers.
Is it because I use some resource consuming functions? Can it be improved?

Google Sheets - Using ArrayFormula with Conditional and Embedded Formula

This may be far more simple than I think. What I'm trying to do is use the ArrayFormula to copy an existing formula to all the rows in a particular column.
To begin with, I have several columns along the lines of:
What I'm doing is adding the first three numbers and multiplying them by the fourth. I also have an IF condition in which, if the fourth column is blank, I leave the value in column 5 blank.
Now, I'm trying to convert this to an ArrayFormula to repeat this for all the rows in column 5.
So I went from:
=IF(ISBLANK(E2)=TRUE,,SUM((B2+C2+D2)*E2))
to this:
=ArrayFormula(IF(ISBLANK(E2:E)=TRUE,,SUM((B2+C2+D2)*E2)))
But what this does is, when I add a new row, ALL of the values in column 5 are set to the same value. Here is an example:
So, my first thought was to set the range on the SUM formula and change it to:
=ArrayFormula(IF(ISBLANK(E2:E)=TRUE,,SUM((B2:B+C2:C+D2:C)*E2:E)))
But that just makes all the values to sum of all of what the individual values should be...so, in my example, it works out to 435 (60 + 135 + 240).
What am I doing wrong here? The values in column 5 should be different in each row (e.g., row 2 should be 135 and row 3 should be 240).
Thanks!
use:
=ARRAYFORMULA(IF(ISBLANK(E2:E)=TRUE,, (B2:B+C2:C+D2:D)*E2:E))
SUM is not supported under AF

Google Spreadsheet Last X Rows

I'm using charts in Google Spreadsheet to plot the last 90 days of data. However, when adding new data it's outside the charts currently selected range of A1:A90. Is there a function I can use to select the last 90 rows of data in a column of a Google Spreadsheet?
You can create a new sheet and use the QUERY function to get the last 90 rows:
If column A is unique and sortable, you simply sort your data in reverse order and take the top 90 rows, and then reverse sort it again:
=SORT(QUERY(Sheet1!A:Z,"order by A desc limit 90"),1,1)
If that is not the case, then you need to calculate the offset by finding the last row and subtracting 90 from it, and then query the data to return 90 rows starting from that offset:
=QUERY(Sheet1!A:Z,"limit 90 offset "&(COUNT(Sheet1!A:A)-90))
You can then use this sheet to generate your chart.
No to my best knowledge, unless you write own google spreadsheet script and use ranges. Script can programatically feed chart with data by
opening Spreadsheet & Sheet
getting data
isolating range, e.g. last 90 rows
feeding with that range the chart component
You can also use the SORTN function to achieve the required result if one or more of your columns are sortable.
In the example below the last 90 rows are listed in descending order with the first sort reverse sorting them back to ascending order:
SORT(SORTN(Sheet1!A:Z,90,0,1,0),1,1)
If you wish to list the last 90 rows after filtering on a particular attribute you can combine the above with a filter function:
SORT(SORTN(FILTER(Sheet1!A:Z,filter to be applied),90,0,1,0),1,1)
If required you can also list the second last 90 records (91 to 180 from last) by applying two SORTN functions as follows:
SORTN(SORTN(Sheet1!A:Z,180,0,1,0),90,0,1,1)

Resources