How to group multiple cells with the same values in Excel - 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.

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.

Convert stock transactions into daily holdings in Excel

interested in converting a transaction statement like so:
Date (DD/MM/YY)
Stock
Flow
11/12/20
Apple
200
12/12/20
Microsoft
50
13/12/20
Apple
-100
into something that looks like:
Date (DD/MM/YY)
Apple
Microsoft
10/12/20
0
0
11/12/20
200
0
12/12/20
200
50
13/12/20
100
50
14/12/20
100
50
Appreciate tips on the best way to go about doing so as I'm not quite sure how to approach this, thanks.
Formulas: (using O365) slightly different approach may be needed in other versions
*note that I created a table out of your stock flow data
F1: Date
G1: =TRANSPOSE(UNIQUE(stockFlow[Stock]))
F2: =ROW(INDEX($A:$A,MIN(stockFlow[Date])-1):INDEX($A:$A,MAX(stockFlow[Date])+1))
G2: =SUMIFS(stockFlow[[Flow]:[Flow]],stockFlow[[Stock]:[Stock]],G$1,stockFlow[[Date]:[Date]],">="&$F$2,stockFlow[[Date]:[Date]],"<=" & $F2)
Select G2 and fill down and across as needed.
Use a Pivot table - create a pivot table, Make "Date" a row and "Stock" a column. Then make "Flow:" a value and change the "Value Field Settings" to "show values as" a "Running Total In..." with "Date" as the base field.
Note that the pivot table will not insert dates that aren't in your raw data, but you could insert rows for the missing dates with a zero flow for any stock to get the table you want:

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

LOOKUP function in Excel to search values on left and right

The scenario I'm facing is that in my company we have mixed naming conventions for servers and workstations like:
COUNTRYCODE-WORKSTATION1
WORKSTATION10-COUNTRYCODE
COUNTRY-SERVER1
SERVER1-COUNTRYCODE
So sometimes I may find names like: BR-WK1 or SRV42-US.
I need to create a PivotTable to extract the amount of events per country so I need to come up with a Lookup function that looks at the first two characters in a cell and if it finds a country code it returns the country code in a country column for that row. If it does not find a country code, it looks at the first two characters on the right, and so on. Country code list will be available in another sheet.
IF(LEFT(CELL,CHARNUMBER){COUNTRY LIST}) then (CELLCOUNTRY == {MATCH COUNTY}))
ELSE(RIGHT(CELL,CHARNUMBER){COUNTRY LIST} then (CELLCOUNTRY == {MATCH COUNTRY}))
Excel:
COUNTRY MACHINE NAME EVENT DATE TIME
BR BR-WK1 Critical type 1 08/01/2015 01:15
US SRV42-US Critical type 2 08/01/2015 01:15
BR WK100-BR Warning type 8 08/01/2015 01:15
US US-SRV420 Critical type 1 08/01/2015 01:15
Pivot table:
Row Labels Count of EVENT
BR 2
US 2
Grand Total 4

Resources