Grouping rows together in excel if they are scattered based on a field - excel

Lets say we have an excel with customerid and amount . If i sort the excel on amount my customers will be scattered. So i want to achieve sort and then group same customers amount tohether maintaining that sort.
If i have below
Row 1 . X 200
Row 2. Y 245
Row 3. Z 45
Row 4. Y 456
Row 5. Z 23
Row 6. T 5678
I want output as :
T 5678
Y 456
Y 245
X 200
Z 45
Z 23

When you select a single column and perform a sort, it disregards values from other columns. So, before sorting your Excel sheet, you need to select the entire sheet:
After that, choose "sort" from the menu, and select sort by column A and then by column B:
Result:

Please see the sorted data on Column B (modified data for Z as 999).
Sorted on Column B
Now below is the result i want to achieve.That is , after sorted on Column B , the rows should re-arrange such that the customers data gets together. Result as below, we can see that 2nd last row z 999 had to be moved , putting below Z 23.
Final Result

Related

Compare two columns and get the values from another column?

I have an excel table with multiple columns, I need to add value for every transaction_id, how can i compare column C with column J and enter values from K into D column?
Table looks like this:
C
D
J
K
transaction_id
amount
transaction_id
amount
1
5
1000
2
1
1000
5
118
200
118
117
500
I need to match the exact transaction_id and move from the right to left amount value if transaction id is the same, how can I do that?
Just use VLOOKUP:
Formula in D is:
=VLOOKUP(C2,$J$2:$K$5,2,FALSE)

List result of lookup A in B, B in C without helper column

I have 2 tables:
Table1 containing Customer & Part#
Table2 containing Part# & Type
(The actual data lists are larger)
Table1 (Customer & Part#) & Table3 (Helper):
Customer
Part#
Helper
A
1
X
B
2
Y
C
3
X
A
4
Y
A
5
X
A
5
X
A
2
Y
Table2:
Part#
Type
1
X
2
Y
3
X
4
Y
5
X
Desired result for combination of customer A and Type X:
Part#
1
5
5
These being the 3 results of part numbers in Table1 that are Customer A and the lookup of the Part# results in Type X (see also Helper column).
I'm able to retrieve the results by creating the helper column as shown in the example data, however I want to skip this column and solve it in one go. But I don't know if that's even possible.
I was thinking about something in this direction.. =INDEX (Table1[Part'#],IF(Table1[Customer]="A",ROW(Table1[Customer]))
..but there I get stuck. I think I can pickup from there with IF, ISNUMBER, SEARCH but my head errors there.
Does anybody know a way to skip the helper column for this?
PS I have office365, but FILTER is not yet released by company rules (unfortunately).
PS I prefer a formula solution, but VBA is allowed when necessary
Here is a formula solution for Excel version 2010 to 2019
In I3, formula copied down :
=IFERROR(INDEX(B:B,AGGREGATE(15,6,ROW(A$3:A$9)/(VLOOKUP(N(IF({1},B$3:B$9)),D$3:E$7,2,0)=H$3)/(A$3:A$10=G$3),ROW(A1))),"")

Aggregating records with two main IDs in [VBA macro]

I want to make a macro in Excel that summarizes data from rows that match a composite ID generated from 2 ID columns. In my excel sheet, each row has 2 main ID columns: ID_1 is the main key, and ID_2 is a secondary key from which I only care about the first 2 letters (Which I have gotten using LEFT). I want to group rows with the same ID_1 and first 2 letters of ID_2 and report the SUM of the value, count, and sum columns.
In the example picture below, I want to turn the data in columns A:J into the data in columns M:V
So, with this example -> We have 6 records 1015 (ID_1) with 3 different ID_2 (AB, AZ, AE). I want to sum them up to a one cell each (1015 AB ; 1015 AZ ;1015 AE) with values which each record had (there is 3 records: 1015 AB with VALUE of 2,3,4 so in result I want to get just one row 1015 AB 9(sum of value) 4(sum of count) 17 (sum of(value * count)). It's important to see that this 17 dosn't come from 9 * 4. It's =sum(I4:I6) (but it may be spread out like in 1200 FF example below! I am still trying to sort them both at one time, but I cant get past it..)
Add a helper column in D to combine the ID_1 and the first 2 characters of ID_2. =A4 & LEFT(C4,2). Copy that down then go to L4 and type in:
=+INDEX($D$4:$D$25,MATCH(0,COUNTIF(L$3:L3,$D$4:$D$25),0)
and hold down Ctrl + Shift + Enter to make it an array function. Copy down to get a list of unique combinations, and then split these values into the separate columns.
Finally to pull in the numbers, put this in Q4:
=SUMIFS(E$4:E$25,$A$4:$A$25,M4,$C$4:$C$25,O4 & "*")
and then copy down and across.

Excel formatting without VBA

So I have some results which may or may not have totals. In this case food. Each food is given an amount and a weight total. I have information below the results however which I do not want to shift. I would use a table however, if I hide rows, it shifts items up. If I sort the rows, the name of the food with no results will still show. Any idea how I could reformat my results into food with results only in a new referenced cell? I'm trying to automate this with no button pressing, and without using macro's/vba's. I could use something like =IF(ISBLANK(B21),"noResults",A21) but how could i list them all like my example blelow?
a1 b1 c1
Amount Weight
x Apples 5 10
x Oranges
x Peaches 6 10
x Lemons 2 10
x Tomatos
x Avacados 3 10
x
x
x xxxxdon't shift or move xxxxxxxxx
TO:
x g1 h1 i1
x Amount Weight
x Apples 5 10
x Peaches 6 10
x Lemons 2 10
x Avacados 3 10
x
xxxxxxxxdon't shift or move xxxxxxxxx
If you can add an ID column to the foods, you could do the following using the SMALL() function:
=IF(D3<>"",B3,"")
=IFERROR(SMALL($F$3:$F$8,ROW(C1)),"")
=VLOOKUP(H3,$B$3:$F$8,2,FALSE)
To Explain Further
The SMALL() function takes an array of numbers and will return the 1st smallest, 2nd smallest, or whatever smallest number you specify. Because this example only has Food names, I had to add an ID column (column B) to get an array of numbers.
Since we only want to view rows with data (amount & weight), I added another column ID Formula (column F) to only display the ID if the column has data.
Now that we are only displaying ID's with data, we can use the SMALL() function to get the 1st smallest ID still showing, then the 2nd smallest ID still showing, and so on... notice that I used the ROW() function to get 1,2,3...
Lastly, I used a simple VLOOKUP() to add in the Food, Amount, and Weight for the respective ID's.

How to get the latest date with same ID in Excel

I want to Get the Record with the most recent date as same ID's have different dates. Need to pick the BOLD values. Below is the sample data, As original data consist of 10000 records.
ID Date
5 25/02/2014
5 7/02/2014
5 6/12/2013
5 25/11/2013
5 4/11/2013
3 5/05/2013
3 19/02/2013
3 12/11/2012
1 7/03/2013
2 24/09/2012
2 7/09/2012
4 6/12/2013
4 19/04/2013
4 31/03/2013
4 26/08/2012
What I would do is in column B use this formula and fill down
=LEFT(A1,1)
in column C
=DATEVALUE(MID(A1,2,99))
then filter column B to a specific value of interest and sort by column C to order these values by date.
Edit: Even easier do a two level sort by B then by C newest to oldest. The first B in the list is newest.
Do you need a programmatic / formula only solution or can you use a workflow? If a workflow will work, then how about this:
Construct a pivot table of your data
Make the Rows Labels the ID
Make the Values Max of Date
The resulting table is your answer.
Row Labels Max of Date
1 07/03/13
2 24/09/12
3 05/05/13
4 06/12/13
5 25/02/14

Resources