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

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.

Related

EXCEL formula to sum demand per date when multiple entries of dates exist

How do I sum the amount of demand I have for each date, when there are multiple entries for each date., e.g.
Sheet 1:
A B
Date Demand
13/7/21 5
13/7/21 4
13/7/21 2
15/7/21 6
15/7/21 3
16/7/21 2
16/7/21 4
So I'm trying to get a summary as follows:
Sheet 2:
A B
13/7/21 11
14/7/21 0
15/7/21 9
16/7/21 6
17/7/21 0
I've tried =SUMPRODUCT(--('Sheet 1'!$A$2:$A$240='Sheet 2'!A2),'Sheet 1'!$B$1:$B$240)
I'm not wanting to do a pivot table, as the pivot table does not give me the zero values for dates where there is no data (unless there is a way to show this in a pivot)
You can use SUMIFS() like
=SUMIFS(Sheet1!B:B,Sheet1!A:A,A1)
You can also use SUMPRODUCT() in this way.
=SUMPRODUCT((Sheet1!$B$2:$B$8)*(Sheet1!$A$2:$A$8=A1))
Put together quickly to start you off:
Edit to give text version of the solution to the OP's problem:
=SUMIFS(B6:B12,A6:A12,"="&G12)
Then you can do between by setting lower and upper criteria in the sumifs().

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

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)

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.

How to Combine Columns with the Same Heading in Excel

I have a set of cost data for different pieces of unique equipment. Each piece of equipment is classified as a particular equipment class which I have pulled from an index match on the unique equipment number. I now have a set of ~9000 columns of cost data, each with a column header of one of the ~300 equipment classes.
What I want to do is to get the median, 25%, and 75% for the full data set for each of these equipment classes.
I either want to create a single long column of all the data for each equipment class, or have a way to calculate the Percentile() values for the data in all columns with the same heading.
I could filter the data for each equipment class one at a time and calculate the percentile values, but with 300 equipment classes it would take forever.
Example:
Class01 Class02 Class01 Class03 Class03
1 4 7 10 13
2 5 8 11 14
3 6 9 12 15
And I want the 25%, median and 75% for the distribution for Class01, Class02, and Class03
Thank you for your time.
I either want to create a single long column of all the data for each equipment class, or have a way to calculate the Percentile() values for the data in all columns with the same heading.
I'll just tell you how to change your data around. From there the percentiles/ quartiles will be straight forward.
Start with your data like this. Notice that I added a column on the left. It's easy to make, just type Item1 and drag down (or double click the small square in the bottom right corner of the cell)
You then need to hit Alt+D+P.
Select multiple consolidated ranges > next
Next (create page ranges for me...)
Select all of your data as the range, click add then finish
You will now get a pivot table that looks like this:
Click the grand-grand total (i.e. 120) and that will create another pivot table like this:
Et voila...

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