Adding additional rows to data based on multiple criteria - google-sheets

I'm working on a project to create a template that uses one of my regular exports and changes the way the data is structured. I've attached a sample spreadsheet below.
https://docs.google.com/spreadsheets/d/1mFo_VpdeXpWkpLqMNnCBAT_93rx_JCjG508VsEwMoL4/edit?usp=sharing
The "Source Data" tab is my export, it's a list of orders where rows are repeated for each unique product that the customer has purchased. The Order Numbers are repeated for as many rows that the order has.
I'm trying to add additional row(s) to each order on my "Corrected Data" tab based on conditions and perform a calculation that would change the data that the additional row outputs.
The conditions / rules are as follows.
To add any additional rows the "Shipping Cost" of the order (column O) must be > 0
If an order has all products with a Tax Class of > 0 then 1 additional row should be added. The Order Number needs to be the same, the "Product Code" (column J) should have "TAXABLE-SHIPPING", the Product Name (column K) should be "Taxable Shipping" and the "Product Price" (column T) needs the following calculation: ROUNDDOWN((ShippingCost/(100+TaxClass)*100),2). Every other column can remain blank.
If an order has all products with a Tax Class of 0 then 1 additional row should be added. The Order Number needs to be the same, the "Product Code" (column J) should have "ZERORATED-SHIPPING", the Product Name (column L) should be "Zero Rated Shipping" and the "Product Price (column T) should be the same as the "Shipping Cost".
If the order has a mixture of Tax Classes then 2 additional rows should be added. The Order Number needs to be the same for both rows, one row should have "Zero Rated"and "ZERORATED-SHIPPING" in the Product Name/Code Columns and the other row should have "Taxable Shipping" and "TAXABLE-SHIPPING". respectively.
The "Product Price" on these two rows needs to do the following calculations and apply to their respective rows.
ZERORATED: ROUNDDOWN(((SUM(Product Prices that have 0 Tax Class)/Order Subtotal)*Shipping Cost),2)
TAXABLE: ROUNDUP(((((SUM(Product Prices that are > 0 Tax Class)/Order Subtotal)*Shipping Cost)/(100+Tax Class)*100),2)
So far, I've managed to get this working with a bit of help to the point where 1 additional row is being added when the Shipping Cost is > 0. This is only with a few select columns rather than the whole dataset. This can be seen in the "Partial Solution" tab.
I don't even know where to begin with the 2nd additional row with multiple tax classes, or how to wrap the calculations into that.
I appreciate that this one is quite lengthy and difficult, perhaps formula isn't the best solution here but I was hoping a single cell array formula would be able to do this. Any help at all pointing me in the right direction would be hugely appreciated! <3

Related

Getting the minimum value in a row and the cell above it

So I have a file of the form above. The hyperlinks you see in row 2 are suppliers. Under each supplier there is the cost for the EAN in that row (EAN is in column A). I am trying to return in column B the minimum price + the supplier that is offering that. How can I do this?
So far I have just done min(rowX) to get the minimum price (as you can see in column B), next I imagine I can use ampersand to concatenate this to the supplier in question but not sure how to use "offset" (or otherwise) to get the supplier? For example, in column B, the first entry should become:
"11.77 - FennixBrokers"
This is in reference to the fact that the minimum price offered by any supplier for this EAN is 11.77 and in this case that happens to be an offer from FennixBrokers.
try:
=BYROW(C3:Z,LAMBDA(z,IF(COUNTA(z)=0,,MIN(z)&" - "&FILTER(C2:Z2,z=MIN(z)))))

Ho to do the automation to calculate the quantity left, profit and loss when there is new data input in google sheet?

Hi everyone,
I have 4 ranges of data:
A1:C5 (Product In Storage), there will be new data input if there are other new products coming in.
E1:G8 (Sales), this is the record for all the products that are being sold, there will be new data input also in the future.
I1:K5 (Summary of Sales), this will record the Quantity Left in the storage and also the total Profit or Loss after doing some calculation based on A1:C5 and E1:G8. The number of rows for Summary of Sales should be equal to the number of rows of Product In Storage (So I'm using query function highlighted in yellow).
M1:O5 (Desired Output), this is the final result that I want to achieve for this task.
My goal is to calculate the Quantity Left & Profit or Loss in Summary of Sales automatically once there are new data input in Product In Storage & Sales.
I'm not sure how to do it because the number of rows in Sales is a not a constant. In this example, the are 2 rows data for Product ID: 1001.01 & 3 rows data for Product ID: 1002.01. In the future, after the remaining quantity (34) for Product ID: 1001.01 had been sold, it need to be included in the Summary of Sales as well.
I attached the google sheet link below in case you need it: https://docs.google.com/spreadsheets/d/17coke3-oyDRLHgz79PDl3KX68kFOEte-aynVe-xEITU/edit?usp=sharing
Is there anyway to do this without using the google apps script? Any help will be greatly appreciated!
For your example,
J4 -> =SUMIF(A:A,I4,C:C) - SUMIF(E:E,I4,G:G) means;
(First sumif, get inventory) Whenever you see I4 in A:A column, get the C value on that row and sum all of them.
(And minus)
(Second sumif, minus sales) Whenever you see I4 in E:E column, get the G value on that row and sum all of them.
(Result) = Get storage quantity and substitute the sales quantity.
K4 -> =ArrayFormula(SUMPRODUCT(IF(E:E=I4,F:F*G:G)) - SUMPRODUCT(IF(A:A=I4,B:B*C:C)))
means,
(get income) if you see I4 on E:E column, then get the sum of (F*G)
(minus)
(get expense) if you see I4 on A:A column, then get the sum of (B*C)
But if i were you, to keep things more simple, i would put =Quantity*Price right of your tables and you can solve problems with only =SUMIF formulas. FYI, this will update everytime you change a value from table so when things get nastier, it will become slower indeed. When that time comes, a VBA macro button or Formulas->Calculation method will save your day.

Google Sheets Formula: List item from Column A if Column B is < or > a given value

I'm working on listing out a long list of "battle items" for a game. I need to categorize them into their Tiers (Tier 1 are battle items of a worth less than 1000 t, for example). I'd like for Google Sheets to do this automatically, rather than go through the list by hand.
Google Sheet Image Cap
End result would be:
Sheets checks based on criteria (< 1000, > 1000 but < 50,000, or
50,000+).
Sorts the list of items (col a) under the tiers as
appropriate. (Tier 1 = > 1000, Tier 2 < 1000, Tier 3 50,000+)
The Name of the Item is listed under the correct Tier.
I'm not looking for a total, I'm not looking to count how many, I just need it sorted.
Example of what I want it to do.
I would count myself a Beginner (just under the intermediate) level of Google Sheets User - I know enough to do some things, but not enough to do really advanced arrays and the like. This is where my knowledge breaks down, as I'm not even sure if what I'm trying to do can be done.
I have searched with Google, looked through the Sheets help files and questions posed by others, and haven't found what I needed. I have tried Query, but my formatting may be wrong?
Create a helper column named Tier in Column C:
C2 =ARRAYFORMULA(IF(B2:B6>50000,3,IF(B2:B6>1000,2,1)))
Now create a new table:
E1:
=TRANSPOSE(UNIQUE(C2:C6))
E2:
=FILTER($A$2:$A$6,$C$2:$C$6=E$1)
Drag fill to the right.

Printing sheets of labels in SSRS 2008 based on data in a table and specific quantities per label

I need to come up with a form in SSRS 2008 that prints labels based on information stored in a table or tables. So far I have been unsuccessful in my online searching. How do I tell SSRS that I want the KitOrder.QuantityCommitted quantity of labels to print for each item? (each item has it's own quantity) I will likely be printing labels for 20-30 items at a time. In case it's helpful to know, there are 18 blank labels per sheet.
edited 10/01/15
Sorry, I played around with with the example you gave and wasn't able to get my report to work. I am not an expert with SSRS.
I have 2 tables I am using to get the info I need for the labels and only need the columns listed below the table names at this point.
KitOrder INNER JOIN Item
KitOrderNumber ItemNumber
Quantity ItemDescription
I am using KitOrderNumber from a dropdown box - IN(#KitOrderNumber) - as my Parameter. The ItemNumber and ItemDescription print on the label. Would there be some custom code I could use that would return 3 labels when KitOrder.Quantity = 3 instead of just 1 label?
Edited 10/05/15 - I was finally able to get my report to work as needed. Thanks so much for your help. The sqlfiddle was quite helpful to me.
I hate when people suggest this when it's not necessary but I think this is one of the times that you'll need to manipulate your data in SQL before the report.
I can't think of an easy way to do it with SSRS that doesn't involve a lot of code.
You create a temp table with your possible quantities then cross join your table to create a separate record for each product based on the number in your Quantity field.
;WITH Quantities AS (
SELECT 1 AS Num
UNION ALL
SELECT 1 + Num
FROM Quantities
WHERE Num <= 30
)
Select * from Products
CROSS JOIN Quantities
WHERE Num <= Quantity
This assumes that your data is in a table called Products.
If you have a query, you can SELECT your fields INTO a #Temp table and use that in the Select statement.
For the report, you can set the Columns peoperty on the Report to use as many columns as your label sheet has.
Here's an SQLFiddle I made that you can play with:
http://www.sqlfiddle.com/#!3/bb413/2

Tricky getting average for price when summing extended and qty

The data we display is summarized by order type. Data looks: where ABCDE is the sum of one or more rows with same item #.
Item Order Type QTY PRICE EXT. PRICE
ABCDE INT 10 $100
I am not displaying price because this row is a summary of several in time frame selected. Price on these items changes in time or for customer.
So What I can do is give an average price.
I have 2 formulas but the result is not correct. all result is same number 91,979.00
formula 'new avg' sum({DATA_WHSV3.ITEM_PRC$}) / count({DATA_WHSV3.ITEM_PRC$})
then If {#new avg} > 0 then
sum({DATA_WHSV3.ITEM_PRC$})/{#new avg}
You can use a Running Total Field to do the average for you. So say your report is grouped by Item# you would create a new Running Total Field.
Running Total Name: RTotal0 (can be anything, this is just the default)
Field to Summarize: {DATA_WHSV3.ITEM_PRC$}
Type of Summary: average
Evaluate: For each record
Reset: On change of group: Group #1: DATA_WHSV3.ITEM_NUMBER
Then you can drop the {#RTotal0} into the group footer along with the other details for that item number and it should be the correct average.

Resources