How to calculate values dynamically from Excel table - excel

I have a programming issue in Excel that I don't know how to solve it. I want to create an automatic Delivery Cost Program on Excel that will help me calculating the cost more easily.
The input variables are:
Quantity (Values for 1, 2-9,10-49,50+ and more)
Shipping method
Depending on the Quantity Value and Shipping method, Excel should lookup on the table and return the total shipping cost according the following Table:
------------------------------------------
Delivery | Per shipment fee
------------------------------------------
| 1 2-9 10-49 50+
------------------------------------------
Standard | 2,99 1,89 1,5 1,1
Expedited | 5,99 2 1,75 1,25
Priority | 10,99 3,39 2,25 1,35
------------------------------------------
Let me show you with some examples what I want to get:
1- Example:
- Quantity: 15
- Delivery: Expedited
- Total Cost = 15 * 1,75 = 26,25$
1,75$ is the returned value after looking on the table using the variable Quantity and Shipping Method.
I have tested doing =IF statements but sure that there is an easier way to do it.
I'm not very good on Excel programming so any help will be appreciated
Best regards and have a great day!

Assuming that your table has the delivery types in column A in rows 4 through 6 and that the quantities are in row 3 (columns B through E) the following formula should do it for you:
=INDEX(B4:E6,MATCH(B9,A4:A6,0),MATCH(C9,B3:E3,1)) * Quantity
Note, that the quantities in row 3 must be a number. So, the numbers should be 1, 2, 10, and 50 and not 1, 2-9, 10-59, 50+. There are two possibilities to achieve that:
Create a helper row and hide it (while only showing the row with the "names" as you wish for.
Change the number format on these cells: for the column containing the 2 the number format should then be "2-9" (custom number format). For the number 10 the number format would be "10-49" and the number format for the last column would be "50+". Like this you see what you wan to see while the cells still contain numbers only (for the upper formula to work correctly).

Related

Cumulative prices based on dates that cover different pricing periods

I am trying to calculate how much someone needs to pay me, where the ticket prices are set for a certain period.
Guest Name | Arrival Date | Departure Date | adults | Child | Total |
J.Bloggs | 14/11/2019 | 18/11/2019 | 5 | 2 | 7 |
Price 01/11/2019 ~ 04/11/2019 = £3.40
Price 05/11/2019 ~ 15/11/2019 = £2.50
Price 16/11/2019 ~ 30/11/2019 = £1.90
I need to workout how to charge J.Bloggs £2.50 for 2 nights (14th & 15th) then £1.90 for 3 nights (16th, 17th and 18th) = £10.70 * 7 people = £74.90
The blue columns is the raw data, the green columns are formula based (I don't need the Price column, I was just using to work out the fees).
This is the formula I have in the price column at the moment, but know that won't work when the tickets are covering multiple periods.
{=INDEX(Pricing!$C:$C,MATCH(1,(Pricing!$A:$A<=IF(ISTEXT($A2),DATEVALUE($A2),$A2))*(Pricing!$B:$B>=IF(ISTEXT($A2),DATEVALUE($A2),$A2)),0))}
Use SUMPRODUCT with INDEX/MATCH:
=SUMPRODUCT(INDEX($C$8:$C$10,MATCH(ROW(INDEX($ZZ:$ZZ,A2):INDEX($ZZ:$ZZ,B2)),$A$8:$A$10)))*E2
this is an array formula and requires the use of Ctrl-Shift-Enter instead of Enter when exiting edit mode.
ROW(INDEX($ZZ:$ZZ,A2):INDEX($ZZ:$ZZ,B2)) creates an array of the dates.
MATCH(...,$A$8:$A$10) Takes that array and finds where it falls in the lookup table. Note: the lookup table must be sorted ascending.
INDEX($C$8:$C$10,...) Takes each of those matches in turn and creates an array of the output prices.
SUMPRODUCT(...) adds all the values together.
Then we simple multiply it by the number of guests.

Search a Column for Specified Text, Then Return the Sum of the adjacent column which contains values to sum

I am creating a World Cup spreadsheet.
Example:
Team | Pts |
Brazil | XXX |
Switz. | XXX |
C. Rica| XXX |
Serbia | XXX |
I have another table which displays the Country, Score & whether it was a W (win), L (loss) or T (tie). A WIN will add 3 points, a TIE will add 1 point & a LOSS will add 0 points. Where I put the XXX, I want a formula that will search the table column for the Country Name and ADD up the W's, L's & T's and display the sum of every game there team played with the point system I mentioned.
Any help would be greatly appreciated! Thanks.
Try,
=SUM(COUNTIFS(D:D, A2, E:E, {"T","W","W","W"}))
You can use COUNTIFS. I set up a mock table to demonstrate:
The first COUNTIFS will count a given teams wins, and then multiple by a factor of 3.
The second COUNTIFS will count a given teams ties (no need to multiply here).
Since a Loss equates to 0 points, there is no need to sum or count anything.
Adjust ranges to fit your setup and then auto-fill the equation down your table to calculate for each team.
You can use a formula in H2, as below, and drag down as many rows as required
=(3*SUMPRODUCT(--($A$2:$A$13=$G2),--($C$2:$C$13="W"))+SUMPRODUCT(--($A$2:$A$13=$G2),--($C$2:$C$13="T")))
Data:
You only care about Wins or Ties. So count the wins per country and * 3 and add to that the count of ties, which you don't need to multiply as is 1.
Sumproduct is used to handle the arrays nicely.

Conditional sums based on conditional drop down selections

My excel sheet looks something like this:
Animal | Weight | Date
Dog 5 Jan/1/2015
Cat 2 Feb/19/2015
Cow 9 Jan/2/2015
Cow 6 Jan/1/2015
Dog 1 Jan/1/2015
Dog 4 Mar/1/2015
I then would like a to have out like this where the first column is a drop down, the second is a dropdown as well and the third is a total:
Choose Animal | Choose Month | Sum of all the weight:
[Dog,Cow,Cat] | [Jan - Dec] | [Sum of the animal chosen for that month]
So I would like to choose an animal, then choose a month and it should sum the weight. For example if I chose Dog and Jan the total weight should equal 6 (5+1). I am unsure how to accomplish this as it needs to take the sum from the first section, but the criteria for that section is based on the dropdown values of the the second section (unsure if I can even create dropdowns such as this?)
You can use 'Data' => 'data validation' => 'list' to create drop down options (e.g. have the list of options on a separate worksheet, and select that as source range)
As for the sum calculation, I'm not entirely sure what you are after - but imagine you could use VLOOKUP with the wildcard to discard all the text after the month, e.g. :
=VLOOKUP(A1&"*",[range],[column no. where weight is],FALSE)
Using that value to then sum in the next cell with something like:
=SUM(A2,IF(ISERROR(VLOOKUP(A1&"*",[Range],2,FALSE)),0,VLOOKUP(A1&"*",[Range],2,FALSE)))
Potential problem questions though are for instance...
Does the year in the date not matter at all?
What were you planning for months where there are multiple weight inputs for the animal? (like for 'cow'/'Jan' in your example, if that occurs in your actual data)
Hope that helps you get started though!

Executing a function over a grouped set

I have two columns of data in Excel, one containing dates and the other values 1 or 2 which represent a specific status (like an enum).
Here is an example data set:
2014/07/04 | 1
2014/07/04 | 1
2014/07/04 | 2
2014/07/04 | 1
2014/07/05 | 2
2014/07/06 | 1
2014/07/06 | 1
2014/07/06 | 2
I need to get a graph of the percentages of the number 1 over days; in the above example
July 4th: 75%
July 5th: 100%
July 6th: 66%.
I've tried pivot tables and charts with no luck because I can't write my own function for values (COUNTIF for ones divided by COUNT), only use the predefined ones which aren't of any use.
Does anyone know how I would go about doing this?
You could do this with a pivot chart.
I made up my own data so it doesn't quite match but it is the same idea.
For the pivot table fields I used
Legend Fields:Compare
Axis Fields:Date
Values: Count of compare
For values under Value field settings goto show value as and change this to % of column total and summarize value by Count.
If you only want to see number one just put a filter on the column labels.

Find the top n values in a range while keeping the sum of values in another range under x value

I'd like to accomplish the following task. There are three columns of data. Column A represents price, where the sum needs to be kept under $100,000. Column B represents a value. Column C represents a name tied to columns A & B.
Out of >100 rows of data, I need to find the highest 8 values in column B while keeping the sum of the prices in column A under $100,000. And then return the 8 names from column C.
Can this be accomplished?
EDIT:
I attempted the Solver solution w/ no luck. 200 rows looks to be the max w/ Solver, and that is what I'm using now. Here are the steps I've taken:
Create a column called rank RANK(B2,$B$2:$B$200) (used column D -- what is the purpose of this?)
Create a column called flag just put in zeroes (used column E)
Create 3 total cells total_price (=SUM(A2:A200)), total_value (=SUM(B2:B200)) and total_flag (=(E2:E200))
Use solver to minimize total_value (shouldn't this be maximize??)
Add constraints -Total_price<=100000 -Total_flag=8 -Flag cells are binary
Using Simplex LP, it simply changes the flags for the first 8 values. However, the total price for the first 8 values is >$100,000 ($140k). I've tried changing some options in the Solver Parameters as well as using different solving methods to no avail. I'd like to post an image of the parameter settings, but don't have enough "reputation".
EDIT #2:
The first 5 rows looks like this, price goes down to ~$6k at the bottom of the table.
Price Value Name Rank Flag
$22,538 42.81905675 Blow, Joe 1 0
$22,427 37.36240932 Doe, Jane 2 0
$17,158 34.12127693 Hall, Cliff 3 0
$16,625 33.97654031 Povich, John 4 0
$15,631 33.58212402 Cow, Holy 5 0
I'll give you the solver solution as a starting point. It involves the creation of some extra columns and total cells. Note solver is limited in the amount of cells it can handle but will work with 100 anyway.
Create a column called rank RANK(B2,$B$2:$B$100)
Create a column called flag just put in zeroes
Create 3 total cells total_price, total_value and total_flag
Use solver to minimize total_value
Add constraints
-Total_price<=100000
-Total_flag=8
-Flag cells are binary
This will flag the rows you want and you can grab the names however you want.

Resources