EXCEL: return 1 value from table based on 2 criteria being met - excel

I have a table of shipping prices per number of units and by country. I'd like to have the total shipping cost appear on my order form once the number of bottles and country have been filled in elsewhere on the order form. Any ideas for what formula would do this?
Here's a small part of my table:
1 2 3 4 5 6
France €12.60 €14.40 €17.40 €19.44 €21.36 €23.40
Belgium €20.40 €26.40 €31.20 €36.60 €42.00 €46.80
Germany €20.40 €26.40 €31.20 €36.60 €42.00 €46.80
So for the client shipping to Germany that selects 5 units, how do I get €42.00 to appear in the shipping cost cell?
Thank you

INDEX with two MATCH's.
=INDEX(A1:G4,MATCH("Germany",$A$1:$A$4,0),MATCH(5,$A$1:$G$1,0))

Here is another approach...
Suppose your data is in range A1:G4 including headers,
Put your look up criteria in range A6:B7, and use the following formula to return the desired cost:
=DGET(A1:G4,""&B7&"",A6:A7)

Related

Excel - SUBTOTAL but only where particular criteria is met (SUMIF/AVERAGEIF)

EDIT: The document is set up like a series of dashboards. Some if the data linked to the many graphs is in pivot tables and some just regular tables. Because there are so many graphs, I use some user selection buttons and fields to change what data is shown in these graphs.
Some users open the file in office 2016.
All solutions I found were either limited to 365 or involved creating new data tables or columns which I was trying to avoid as it would mean a fair bit of rework. I instead just used a set of nested IFS and will eventually look at changing these particular pivots to regular tables with index lookups to enable the actual data to be in multiple columns.
I currently use a SUBTOTAL function to either sum, count or average a bunch of cells in a range. I was previously manually filtering the range so I was only totaling the rows I wanted, however the need has arisen to be able to look at several criteria at once.
i.e in the example below, I was previously manually filtering range to only include "Apple" but now I need to be able to total "Apple", "Orange", "Banana" separately, at the same time.
The subtotal fields are used in graphs and I have a cell (F5) that houses a number corresponding to either SUM, COUNT or Average (9, 2 or 1) to use in the subtotal formulas in the "Summary table" which is linked to other functionality within the workbook and I need to still be able to retain that functionality.
Example of how my sheet is setup:
Raw Data
Product Type
Sales QTY
Date
Apple
4
1/9/21
Orange
3
6/9/21
Banana
2
10/9/21
Apple
6
14/9/21
Orange
6
20/9/21
Apple
5
29/9/21
The Criteria I want to match is in Column 1 (Product Type) of the summary table.
Basically, I then want to be able to end up with the ability to display the data either as Totals:
$F$5 = 9
for each line: SUBTOTAL($F$5,SalesQTY)
Summary Table
Product Type
Result (Sales Per Month)
Apple
15
Orange
9
Banana
2
Or as Averages:
$F$5 = 1
for each line: SUBTOTAL($F$5,SalesQTY)
Product Type
Result (Average QTY per Sale)
Apple
5
Orange
4.5
Banana
2
Or as a Count:
$F$5 = 2
for each line: SUBTOTAL($F$5,SalesQTY)
Product Type
Result (# Sales Transactions)
Apple
2
Orange
2
Banana
1
Is there some way I can combine SUMIF and also SUBTOTAL but also be able to retain the ability to flick between average, sum and count?
Here is a formula to create a dynamic summary table in excel 365. If you have any earlier version of excel, the formula would be different and rows would have to be manually added or removed. I'm assuming your table is called Data_Table.
=LET(
Column_Product, Data_Table[Product Type],
Column_QTY, Data_Table[Estimated],
Column_Date, Data_Table[Date]
Column_Key, Column_Product,
Column_Filter1, Column_QTY,
Column_Filter2, Column_Date,
List_Filter1, UNIQUE(Column_Product),
List_Filter2, 1,
Categories, SORT(UNIQUE(Column_Key)),
Array_BoolKey, (TRANSPOSE(Column_Key)=Categories)+0,
Mask1, TRANSPOSE(ISNUMBER(XMATCH(Column_Filter1,List_Filter1))),
Mask2, TRANSPOSE(Column_Filter2>List_Filter2),
Array_BoolMasked, Array_BoolKey*Mask1*Mask2,
Masked_QTY, IFERROR(Array_BoolMasked*TRANSPOSE(Column_QTY),0),
Masked_Date, IFERROR(Array_BoolMasked*TRANSPOSE(Column_Date),0),
Array_Ones, SEQUENCE(COLUMNS(Array_BoolMasked),1,1,0),
Months, DATEDIF(MIN(Column_Date),MAX(Column_Date),"M"),
Body_Count, MMULT(Array_BoolMasked, Array_Ones),
Body_Sum_QTY, MMULT(Masked_FtModeled, Array_Ones),
Body_Average_PerSale, Body_Sum_QTY/Body_Count,
Body_Sum_QTY_PerMo, MMULT(Masked_FtModeled, Array_Ones)/Months,
Total_Count, IFERROR(SUM(Body_Count_Lines),"-"),
Total_QTY_PerMo, IFERROR(SUM(Body_Sum_QTY)/Months,"-"),
Total_Average_PerSale, IFERROR(SUM(Body_Sum_QTY)/Total_Count,"-"),
Array_Seq, {1,2,3,4,5},
Array_Header, CHOOSE(Array_Seq, "Product Type", "Sales Per Month", "Average QTY per Sale", "# Sales Transactions"),
Array_Body, CHOOSE(Array_Seq, Categories, Body_Sum_QTY_PerMo, Body_Average_PerSale, Body_Count),
Array_Total, CHOOSE(Array_Seq, "Total", Total_QTY_PerMo, Total_Average_PerSale, Total_Count),
Range1,Array_Header,
Range2,Array_Body,
Range3,Array_Total,
Rows1,ROWS(Range1), Rows2,ROWS(Range2), Rows3,ROWS(Range3), Cols1,COLUMNS(Range1),
RowIndex, SEQUENCE(Rows1 + Rows2 + Rows3), ColIndex,SEQUENCE(1, Cols1),
RangeTable,IF(
RowIndex<=Rows1,
INDEX(Range1,RowIndex,ColIndex),
IF(RowIndex<=Rows1+Rows2,
INDEX(Range2,RowIndex-Rows1,ColIndex),
INDEX(Range3,RowIndex-Rows1-Rows2,ColIndex)
)),
Return, RangeTable,
Return
)
I wrote this generically so you could add filters for only certain products, or minimum quantity, or a date range, or other criteria. Above, I set up the filter to pass everything.
Solution Used:
To avoid having to rework the many other tables in the sheet that rely on this field and also as some user open this file with older (non-365) versions of excel, I opted for a series of nested IF (CountIF, SumIF, AverageIF) statements instead.

Is there a way to distribute data according to a logic in Excel vba?

I have an Excel sheet with the below data.
There are 10,000 Data rows.
9000 are of "USA" & 1000 are of "Other" country.
I want to evenly distribute the data so that when I have 9 "USA" followed by 1 "Other" data distributed throughout.
Name
Country
Alice
USA
Brook
Other
Cathy
USA
David
USA
Esther
Other
Freddy
USA
Galin
USA
Henry
Other
Indigo
USA
Jenny
USA
Kalin
Other
Linda
USA
How do I accomplish this using manual & excel VBA? Appreciate both solutions. Thanks
This can be achieved with a formula if you have the newest version of Excel.
Try something like (adapt ranges and what you are filtering on as necessary):
=LET(x, FILTER($B$1:$C$12, $C$1:$C$12="a"),
y, FILTER($B$1:$C$12, $C$1:$C$12="b"),
z, ROW(D1:D12), myrows, MAX(z),
ratio, MAX((COUNTA(x)/2)/(COUNTA(y)/2), (COUNTA(y)/2)/(COUNTA(x)/2))+1,
IF(MOD(z,ratio)<>0,
INDEX(x, IF(MOD(SEQUENCE(myrows),ratio)=0, 0, SEQUENCE(myrows)-CEILING(ROW(G1:G12)/ratio-1,1)), SEQUENCE(1,2)),
INDEX(y, IF(MOD(SEQUENCE(myrows),ratio)<>0,0,SEQUENCE(myrows)/ratio), SEQUENCE(1,2))))
For example:
The trick is to create the "correct" sequence for each result; for the first array you want to skip every nth row (in your case 10), and having the nth+1 row not default to n+1, but n, while in the second array you want to skip every row that isn't a some multiple of n, and have the nth rows count sequentially.
A caveat-- as is, I don't believe the formula will work with repetition other than 1, i.e. if you want to do something like 8 rows followed by 2 rows, this won't work.
This works even with older Excel versions:
If this is your data:
Add a Sort column with the following formula in C2 and pull it down:
=IF(B2="USA",COUNTIF($B$2:B2,"USA")+INT((COUNTIF($B$2:B2,"USA")-1)/ROUNDUP(COUNTIF(B:B,"USA")/(COUNTA(B:B)-COUNTIF(B:B,"USA")),0)),COUNTIF($B$2:B2,"Other")*(ROUNDUP(COUNTIF(B:B,"USA")/(COUNTA(B:B)-COUNTIF(B:B,"USA")),0)+1))
Then sort by this column C and USA and Other are evenly spread:

How to group multiple cells with the same values in Excel

I am trying to group multiple cells in Excel to give me an end value of the total of times those three cells exist, for example, if the Country is "UK", the Method is "Method1" and Weight is "400", instead of that appearing 2 times as it does in the table below, I would like to merge it so it is there only once, but the Amount column has a value of "2" to represent how many times it is in the Sheet. The data I am using has thousands of different and varying values. I am using Microsoft Excel 2016.
Thank you.
Current Sheet:
Country Method Weight Amount
USA Method7 200 x
UK Method1 400 x
UK Method1 400 x
FRANCE Method55 3994 x
Desired Sheet:
Country Method Weight Amount
USA Method7 200 1
UK Method1 400 2
FRANCE Method55 3994 1
This is how my original data looks like:
And I can resume it as you need using Pivot Tables
Make sure you set the Pivot Table Value Property as count when
using the field Amount
Just in case it may help, I'm attaching how I set up this Pivot Table to make the operations you need (please, note my Excel is in Spanish, but position of each field must be the same, and the operation in Values section affecting field Amount must be COUNT)
As there is a direct link between country, method and weight, you can use subtotals for that (menu "Data", chapter "Outline", feature "Subtotals"). You configure it as:
At each change in : "Country"
Use function : "Count"
Add subtotal to:
Country (No)
Method (No)
Weigth (No)
Amount (Yes)
Replace current subtotals (Yes)
Page break between groups (No)
Summary below data (Yes)
Your result will look as follows:
By clicking on the numbers 1, 2 or 3 in the left margin, you'll be able to view/hide subtotals for that country.

Excel Vlookup Multiple Values

I am looking for a vlookup formula that returns multiple matches using two lookup values. I am currently trying to use the concatenate method, but I haven't quite figured it out. The table needs to return all of the multiple matches not just one. Currently, its only returning the last match.
For example, lets say I have a list of multiple city and states. The cities differ but the states remain the same obviously. I want to return the number of people in the each city.
City State #OfPeople
Albany NY 10
Orlando FL 5
Tampa FL 3
Seattle WA 1
Queens NY 8
So I concatenated the city and state column.
Join City State #OfPeople
Albany-NY Albany NY 10
Orlando-FL Orlando FL 5
Tampa-FL Tampa FL 3
Seattle-WA Seattle WA 1
Queens-NY Queens NY 8
The purpose of this is to create an updated log of people in each city has time progresses. I want to have a grand total amount of people in each column. (I know this requires another formula. I'm just focused on returning multiple matches for now). However, I don't want to overwrite the existing data. Hopefully, I explained this well. This is just an example of a larger project I'm working on. I need to be able to build on this list. That's why its important that I be able to return matches multiple times.
Join City State #OfPeople Total
Albany-NY Albany NY 10 10
Orlando-FL Orlando FL 5 15
Tampa-FL Tampa FL 3 18
Seattle-WA Seattle WA 1 19
Queens-NY Queens NY 8 27
Any help would be greatly appreciated!
Considering you're trying to get some grand totals based on multiple criteria, I would suggest using SUMIFS() / COUNTIFS() functions, rather than focusing on searching matching row itself.
However, if you need multiple criteria look up, for some reason, I believe INDEX() + MATCH() combination can perfectly do the job.
The table needs to return all of the multiple matches not just one.
Currently, its only returning the last match
You'll need to use SUMIFS() if there are multiple records for the same city/state combo in your people lookup.
=SUMIFS (sum_range, range1, criteria1, [range2], [criteria2], ...)
Let's assume that you have a cities tab and a people tab. Let's assume you have ten cities that you want to return the total amount of people from.
Cities Tab definition
City range: 'Cities'!A$1:A$10
State range: 'Cities'!B$1:B$10
People Tab definition
City range: 'People'!A$1:A$100
State range: 'People'!B$1:B$100
#OfPeople range: 'People'!C$1:C$100
Drop this formula in the first row of your cities tab, drag down the entire range of cities.
=SUMIFS('People'!C$1:C$100, 'Cities'!A$1, People'!A$1:A$100, 'Cities'!B$1, 'People'!B$1:B$100)

How to calculate values dynamically from Excel table

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).

Resources