Tiered Discount Price calculation Google Sheets formula - google-sheets

I'm trying to figure out how to calculate a pricing subtotal based on tiered discount.
I found various examples online for Excel but was not able to grok it and make it work in Google Sheets.
What I'm trying to do is calculate the subtotal for 2 line items based on the green and yellow discount tables:
This would be a correct calculation for 40 site licenses:
20 * 150 + 10 * 120 + 10 * 90 = 5100

try:
=ARRAYFORMULA(SUM({QUERY(({0; I$6:I$12}-I$6:I$13)*-1,
"limit "&MATCH(VLOOKUP(C6, H$6:H$12, 1, 1), H$6:H$12, 0)-1);
C6-VLOOKUP(C6, I$6:I$12, 1, 1)}*
INDIRECT("J6:J"&MATCH(VLOOKUP(C6, H$6:H$12, 1, 1), H$6:H$12, 0)+ROW(H$6)-1)))
spreadsheet demo

The classic approach to this would be
=SUMPRODUCT((C26>H$6:H$12)*(C26-H$6:H$12+1)*(J$6:J$12-n(J$5:J$11)))
Adapted from

Related

Dynamic Row/Column ArrayFormula

Looking for a single ArrayFormula which can populate a matrix calculation where the row and columns are dynamically generated from separate lists.
I have a working ArrayFormula for a single column, but cannot work out how to have this formula auto-populate as new columns are added.
There are separate sheets with Products and Companies. Each Product has attributes Height, Width, and Depth. Each company has criteria for each Height, Width, Depth attribute. A matrix is populated indicating whether a product Height, Width, and Depth fall within the constraints of each company.
Product.Height <= Company.Height AND Product.Width <= Company.Width AND Product.Depth <= Company.Depth
Columns K and L are auto-populated using ArrayFormulas (K3 =query(A3:A,"select A") and L2 =transpose(query(F3:F7,"select F"))) allowing new Products and Companies to be added without having to separately maintain the Matrix.
The ArrayFormula copied across L3:P3 shows the desired result for single Company column:
=arrayformula(
if(
vlookup(indirect("K3:K"&counta($A3:$A)+2),indirect("A3:D"&counta($A3:$A)+2),2,0)<=vlookup(L$2,indirect("F3:I"&counta($F3:$F)+2),2,0),
if(
vlookup(indirect("K3:K"&counta($A3:$A)+2),indirect("A3:D"&counta($A3:$A)+2),3,0)<=vlookup(L$2,indirect("F3:I"&counta($F3:$F)+2),3,0),
if (
vlookup(indirect("K3:K"&counta($A3:$A)+2),indirect("A3:D"&counta($A3:$A)+2),4,0)<=vlookup(L$2,indirect("F3:I"&counta($F3:$F)+2),4,0),
"✔",
"✗"
),
"✗"
),
"✗"
)
)
The goal is to paste a single ArrayFormula in a cell, likely L3, allowing new Companies to be added without needing to manually copy/paste the ArrayFormula across the new Company columns.
The sample sheet combines Products, Companies, and the Matrix into a single sheet for simplicity.
Products A2:D7
Products
Height
Width
Depth
Product 1
10
10
10
Product 2
20
20
20
Product 3
25
30
30
Product 4
30
35
35
Product 5
50
50
50
Companies F2:I7
Company
Height
Width
Depth
Company 1
5
5
5
Company 2
20
20
20
Company 3
25
25
25
Company 4
30
35
35
Company 5
25
25
25
Here's what I would do:
Create another sheet which will list all combinations of Products and Companies.
Use the following formula in cell A2:
=INDEX(SPLIT(FLATTEN(FILTER(Sheet1!A3:A,LEN(Sheet1!A3:A))&"#"&TRANSPOSE(FILTER(Sheet1!F3:F,LEN(Sheet1!F3:F)))),"#"))
In cells C1 to E1 of the new sheet, add the headers Height, Width and Depth.
In cell C2 of the new sheet, add this formula:
=ARRAYFORMULA(IF(VLOOKUP(FILTER(A2:A,LEN(A2:A)),Sheet1!A:D,MATCH(FILTER(C1:1,LEN(C1:1)),Sheet1!A2:D2,0),FALSE)<=VLOOKUP(FILTER(B2:B,LEN(B2:B)),Sheet1!F:I,MATCH(FILTER(C1:1,LEN(C1:1)),Sheet1!F2:I2,0),FALSE),1,0))
This creates a matrix of 1s and 0s; 1 if the company dimension is greater than or equal to the product dimension, and 0 if it is not.
Then in the original sheet, in cell L3, add this formula:
=ARRAYFORMULA(IF(VLOOKUP(FILTER(K3:K,LEN(K3:K)) & FILTER(L2:2,LEN(L2:2)),{Sheet2!A:A & Sheet2!B:B,Sheet2!C:C * Sheet2!D:D * Sheet2!E:E},2,FALSE),"✔","✗"))
This looks up the combination of Product and Company and if all three of the company dimensions are greater than the product dimensions (1 * 1 * 1 = 1), then it shows a check mark, and if not then a cross.
I'm using the cell references in the simplified single sheet you provided, so you'll need to change them obviously.
It's similar to a Sheets challenge that I faced lately, so was glad to share what I found out. Basically, it's easier to have a separate sheet for calculations then use that for a lookup reference.

In Google Sheets, I want to get all data from a specific column where the first column matches my SKU. There are multiple rows with that SKU

I have data that looks like this:
sku
price
level
ab1
1.01
1
ab2
2.06
1
ab2
1.45
25
ab3
2.00
1
ab3
1.40
10
ab3
0.89
25
ac2
0.74
1
ac2
0.50
100
As you can see, I have products that have quantity discounts in one sheet. I need to get these levels and prices out of this sheet and into another sheet.
I need to get all prices and levels for all skus, not just the first match. So if my lookup is for sku AB3 I would expect to find 2.00 / 1, 1.40 / 10 and 0.89 / 25
I have not got an extensive Google Sheets knowledge so I am afraid I have hit a brick wall in what to search for.
What do I need to do in order to get this data from sheet a into sheet b.
I have not yet decided how this data is going to look in sheet b, so I don't know if I want the price and level to go into the same cell like "1.01 per 25" or in separate cells.
You can use FILTER() function.
=FILTER(B2:C,A2:A=F1)
Or QUERY() function like-
=QUERY(A2:C,"select B, C where A='" & F1 & "'")

SUM the total in different spreadsheets

I have two spreadsheets, in 1 I have several recipes with the total. In the other sheet the client can choose 2 recipes. I would like to SUM the total of each selected recipe, but I don't know how to do this in the google spreadsheet. I thought of the following algorithm.
SELECTED RECIPE (COLUMN + 1):(ROW + 4)
i.e If the client select
RECIPE 1 (A + 1) = B : (1 + 4) = 5
TOTAL = B:5
RECIPE 3 (A + 1) = B : (7 + 4) = 11
TOTAL = B:11
use:
=ARRAYFORMULA(SUM(QUERY(SPLIT(TRIM(FLATTEN(
SPLIT(QUERY(FLATTEN(IFERROR(IFNA(REGEXEXTRACT(Sheet1!A1:E,
TEXTJOIN("|", 1, G1:I1))), "♠"&Sheet1!A1:E&"♦")),,9^9), "♦"))), "♠"),
"select Col2 where Col1 matches '"&G1&".+|"&H1&".+'", 0)))
spreadsheet demo
You data is really not set up in a readable format for excel. If you want it to be easier to scale (such as if you have a lot of recipes), you should set up the data to look like this and use this formula
=iferror(index(F19:F20,match(A23,A19:A20,0)),0)+iferror(index(F19:F20,match(B23,A19:A20,0)),0)
If you really want to use your current data format, you could use an if statement for each recipe
=if(A14="Recipe 1",B5,if(A14="Recipe 2",E5,if(A14="Recipe 3",B11,if(A14="Recipe 4",E11,0))))+if(B14="Recipe 1",B5,if(B14="Recipe 2",E5,if(B14="Recipe 3",B11,E11,if(B14="Recipe 4",E11,0))))

Split up combined Google sheet to separate sheet per person

I've been struggling for a couple of days now how to get this to work. I have a set of data that I get in a CSV format, that I will copy past in a Google Sheets workbook.
On sheet 1 I have the following (example) data:
Hours Expertise Responsible Rate Total
4 Cleaning Bob 11 44
2 Cleaning Barb 15 30
3 Woodwork Xander 19 57
1,5 Electricity Bob 22 33
There are only 3 responsible people in this example, and I now need to create a sheet per person, showing only their data, but in the same way as it is in the combined sheet.
So what I would like to end up with (for this example) are 3 sheets:
Sheet Bob
Hours Expertise Responsible Rate Total
4 Cleaning Bob 11 44
1,5 Electricity Bob 22 33
Sheet Barb
Hours Expertise Responsible Rate Total
2 Cleaning Barb 15 30
Sheet Xander
Hours Expertise Responsible Rate Total
3 Woodwork Xander 19 57
But to be honest, I'm kinda lost right now. I couldn't get this to work with pivot table or any of the other things I could find with google. I also tried using Vlookup, but then I end up with empty lines in between.
use:
=QUERY({'sheet 1'!A:E}, "where Col3 = 'Bob'", 1)
=QUERY({'sheet 1'!A:E}, "where Col3 = 'Barb'", 1)
=QUERY({'sheet 1'!A:E}, "where Col3 = 'Xander'", 1)

Custom average function on a pivot table in Google Sheets

I have a spreadsheet that I'm starting to use for personal money analysis.
My main sheet is called "transactions" and has headers of Category, Description, Date and Amount (it's basically a check register).
I've created a pivot report off of that sheet that contains sum, min and max of Amount by Category.
I would like to make a custom average function on that pivot report but not sure how to go about it.
What I would like to see is the average amount of negative transactions between positive ones.
My positive transactions are my paychecks and the negative transactions are any spending I do.
An example might help in what I'm trying to do here...
Let's say for category "Food" I have the following transactions (in this order)...
-20
-25
-30
100
-30
-35
-40
I'd like my average to be calculated like this...
( ( (-20 + -25 + -30) / 3 ) + ( (-30 + -35 + -40) / 3 ) ) / 2
Anyone have the slightest idea on how I can enhance my pivot report to do this?
You do it with something like:
=ARRAYFORMULA(AVERAGE(IF(Sheet1!D2:D8<0,Sheet1!D2:D8, 0)))
where column D is the amount of your example and Sheet1 contains the "transactions" of your example.
If you want to fill it for the pivot table (having the category as another criterion) you can check the answer at: https://stackoverflow.com/a/9165254/179529
=SUM(ARRAYFORMULA(((Transactions!$A2:$A)=$A2) * ((Transactions!$D2:$D)>0) * (Transactions!$D2:$D) ))
/
SUM(ARRAYFORMULA(((Transactions!$A2:$A)=$A2) * ((Transactions!$D2:$D)>0) * (1) ))
where $A2 is the cell where you have the category name in the pivot table (The $ will allow you to copy the formula to other columns in you want it per month or other second criterion.
If you want to SUM the element in column D only if they great than 0, you need to have ((Transactions!$D2:$D)>0) as the second argument and (Transactions!$D2:$D) as the 3rd argument (otherwise you will count the cells instead of SUM them).
Since AVERAGE will take blank cells as well, I've used SUM/COUNT instead. Note that COUNT is actually SUM with the 3rd argument as 1.
Also note that if you want to ignore a header line you need to define your columns with Transactions!$D2:$D, to start from the 2nd row.

Resources