Select value from range based on match - google-sheets

I've got the following set of data and have setup a another table to the right which holds the cost of each location.
The cost column currently I've got =IF(EXACT(B2,"Home"),D2*17.2,D2*0.09), however the cost per kWh can change based on different locations. I want to be able to lookup the cost based on another table which will make things more manageable.

You can put this formula in E2:
=VLOOKUP(B2,$G:$H,2,FALSE)*D2
It will take the value in B2, find it in the G column, take the value from the cell right to that match in the H column. This is the Cost per kWh, so it gets multiplied by D2 to arrive at the cost.
The FALSE is needed to require an exact match.
Drag/copy down the formula to the other cells in the E column.

Related

Having problems converting formulas to arrays

Here is the sample workbook: https://docs.google.com/spreadsheets/d/1FqkXO8sdpeP9GPerdg8o2zcSiTV7o8gA-07iBvqw4Yw/edit#gid=1252102463
I'm working off the size tab but I have a "workingsize" tab that someone helped me with. The formulas in that sheet are working great.
ColN in Size corresponds to ColR in WorkingSize. In the absence of context, I'm looking for those two outputs to be identical and can't figure out how to get the formulas to behave correctly.
For more context on Size:
Eventually, the data entered into the red section will exist on an entirely different sheet. I'm good at referencing between sheets but just wanted everyone to be aware. This is the data I'm having trouble with.
in K6 & below, you enter in a type of pizza. right now it's free text but ultimately, it will be a drop down from the range A2:A. That range also matches the headers in F3:H3. In theory, as new items are added to the A2 range, new columns will appear here.
ColL is a number - it represents a dough ball weight.
ColM is identifying which column from the table to be searching against.
ColN then takes the weight, rounds it to the nearest value in the corresponding col for type, and then outputs the corresponding size.
ColN in Size is my attempt to take the formulas from colR in workingsize and turn them into an array.
You can try with XLOOKUP. With INDEX and XMATCH you narrow the weightes by the match on the name of the column. Then with MAP you can convert it in an array. Change the last -1 to 1 if you want to round it up instead of down:
=MAP(K6:K,L6:L,LAMBDA(type,wt,IF(wt="","",XLOOKUP(wt,INDEX(E4:H,,XMATCH(type,E3:H3)),D4:D,,-1))))
PS: I deleted the column of key value, since it was not necessary
UPDATE:
To find closest value, you can use this: it sorts D column by the absolute value of the difference between the corresponding column and the weight. SORTN and the first 1 returns only the first value, meaning the closest to the weight
=MAP(K6:K,L6:L,LAMBDA(type,wt,IF(wt="","",SORTN(D4:D,1,,BYROW(INDEX(E4:H,,XMATCH(type,E3:H3)),LAMBDA(d,ABS(wt-d))),1))))
Let me know!

Formula for calculating a cell value based on variable percentage bands with specific threshold levels

I have a Google Sheet with two tabs - one containing percentage "bands" values and the other with data in a table which includes rows for new entries and columns off to the right edge which store running totals depending on the entry type. The running totals depend on the row entry being of the same type and month period. This all works as expected.
I need to calculate a value in column I based on a row entry amount/cell (column H) which references the running total for that entry type AA:AF and month and then uses the relevant predefined percentage "bands" values (tab R1).
I had successfully got this working when a single entry would only ever cross one "band" level (the bands were previously tens of thousands apart) by using SWITCH and VLOOKUP functions.
The current formulas in column I use this method which no longer works since the percentage bands are now much closer together than they were before and a single entry could take the running total value for that entry over multiple bands (and not just the previous band, as before).
On the example sheet, cell H6 contains 9,900 as a test value since this increases the running total for that row AB6 to 16,313 from the prior running total for that type, 6,413 and spans 4 percentage bands:
Band A: 0-7,500 - 5%
Band B: 7,500-10,000 - 7.5%
Band C: 10,000-15,000 - 15%
Band D: 15,000 - 25,0000 - 17.5%
My original formula first checks the entry Type using a SWITCH, then matches the highest "band" value using a VLOOKUP and then an IF to check if the previous running total was less than the highest matched "band" value, calculating and adding the difference if needed.
I've tried to figure out how to calculate the same result when multiple bands are crossed (as in example) but I can't find a way to structure the formula so that it can apply universally down the column using the matched band rate(s), previous running total and new running total values.
Is there a mathematical way to do this or will this require multiple nested IF statements etc or would another approach work better?
I solved this by modifying the formulas on this page. Changing the layout of the bands was a good first move.
Now, column I calculates the value from the current running total (matched from type in column A) and subtracts the value calculated in the same way but using the previous running total to give the amount applicable to the newly entered value on the same row in column H. I've some more testing to do but fairly sure it works correctly. Any other ideas, feel free to suggest!
Provisionally working sheet here: https://docs.google.com/spreadsheets/d/1e2pdyOi7dz_ZA8zfNtsHxieEUb5fiZGpD_FwRvkHyYw/edit?usp=sharing

Summing a range based on whether other non-contiguous cells contain text or numbers

I am trying to add a range of numbers only if the corresponding cells contain numerical values.
I am working on a grade tracking document where every assignment contains a different weighting. When students do not write the test an NA is entered. I would like to check which cells contain numerical values and add the corresponding weightings.
In the image above, the '%' column is automatically calculated and I would like this new formula to seek information from the 'Mark'column.
I tried this formula but it doesn't exclude NA and I am unsure how to include ISNUMBER to use this instead, Or maybe there is something else entirely I should be trying.
SUMPRODUCT(--(CHOOSE({1,2,3,4,5,6,7,8},B31,F31,J31,N31,R31,V31,Z31,AD31)>0),CHOOSE({1,2,3,4,
5,6,7,8},L5,L6,L7,L8,L9,L10,L11,L12))
L5 to L12 contain the weightings I would like added. L5 corresponds to B31, L6 to F31 and so on...
I would like to check if B31,F31,J31,N31,R31,V31,Z31,AD31 are numerical values and then add the corresponding cells in Column L.
Are you using SUMPRODUCT because you need to multiply L5*B31,L6*F31.... and sum the result??
If that's so, you can use it like this:
=sumproduct(L5:L12,arrayformula(iferror({B31;F31;J31;N31;R31;V31;Z31;AD31},0)))
It it's a text or an error (that's why the arrayformula and iferror) it will be considered as "0". If "NA" is not an error and there aren't any chances of having one you can just use:
=sumproduct(L5:L12,{B31;F31;J31;N31;R31;V31;Z31;AD31})
Considering your given sample, you could divide this result by a sumif of the total marks of the tests the student actually took. With your new ranges that would be:
=sumproduct($H$4:$H$8,{C15;E15;G15;I15;K15})/sumif({C15;E15;G15;I15;K15},">0",$H$4:$H$8)
Or with the previous ones:
=sumproduct($L$5:$L$12,{B31;F31;J31;N31;R31;V31;Z31;AD31}/SUMIF({B31;F31;J31;N31;R31;V31;Z31;AD31},">0",$L$5:$L$12)
https://docs.google.com/spreadsheets/d/1wjvlK74nbUM7NfvG23fQL_T6fin6FL6YpYAxjsMV9sk/edit#gid=0

Multiple Criteria - vlookup

I have been trying to use an If(and... to grab a lookup if the weight (column F) meets the range on a second sheet between the min and max columns.
For example: If a SKU's weight is between a highsize and a low size on sheet 2 and the helper column matches, then I'd like to pull in the price.
Link: https://docs.google.com/spreadsheets/d/1ermKIQnZRcWzm8ogDE7IK0fQSLohDsOBHuaUjjRi8io/edit?usp=sharing
The helper column is a join of the shape, color, and clarity, however, the carat weight will then decide what the standard industry price for that goes.
Multiple SKUs can have the same shape, color, and clarity so the weight would be the defining factor. I created helper columns to help with that part, however, I am having trouble getting a formula that would combine a lookup and an if weight is >highsize and <lowsize.
The main project I'm working on has many, many, skus so going through each one and copying is not a viable solution. The second part is that the second sheet's prices will update on a weekly basis so I need to be able to update it to populate on the first sheet.
try in P1 cell:
={"E-Price"; INDEX(IFNA(VLOOKUP(B2:B, 'e-Price Ranges'!A2:G, 7, 0)))}

I would like that a numeric list indicate movement when a value in the same row changes to another

An example of what im asking for
Im asking if there's a way to "mark" in the B column when a value changes in position respect at the C column.
Like if new data came and the EXAMPLE1 changes to the C8 cell, that the number in the B8 column show that it has a lower position.
Sheet : https://docs.google.com/spreadsheets/d/1pLYqhkLuAS8ZgjPnsZTZyU5yuPXVgm0IRUPIF2FBKkM/edit?usp=sharing
Google Sheets are better formulated in numeric value. In view with your screenshot provided, I saw player, and I assumed your player comes with various other numerical value along such as scores, age, weight, etc.
With the aid of the numerical value, you can formulate a deductive relation by finding who is best ranked number 1.
Here's an example:
As you can see from the picture above, assumed the greater the age, the higher the rank, you may use countif to count the other bigger value, while you can combine use count for deduction, and that builds the sequence from getting number 1 the older, and last the younger
Hope you find it helpful

Resources