Extract values from column based on other column EXcel function line code - excel

New to Excel : Problem
Sample table Below :
Company | Product | |Total Sales
AAA QQQ 123
BBB QQQ 140
CCC WWW 127
DDD WWW 145
CCC QQQ 190
DDD QQQ 290
AAA WWW 240
BBB WWW 120
AAA RRR 123
BBB RRR 122
CCC RRR 178
DDD RRR 789
Desired output : Same Table should be sorted by companies and products arranged according to total sales:
(Company names need not to be sorted but should be clumped together)
Desired output:
Company Product Total Sales
AAA WWW 240
AAA QQQ 123
AAA RRR 123
BBB QQQ 140
BBB RRR 122
BBB WWW 120
CCC QQQ 190
CCC RRR 178
CCC WWW 127
DDD QQQ 290
DDD RRR 789
DDD WWW 145
The sheet is too big to do it manually. Is there any way to automate the process in excel . If so Please help. Solution should be by functions only no pivot table or VBA.

It appears that all you want to do is sort your data on the Company and Total Sales columns, in that order. In this case, you can just highlight your table in Excel and then press ALT + D + S. This will bring up a sorting dialog box, as the screen capture below shows. Note: include the column headers when you select the data (despite what the screen capture shows).
Just choose Company as the first sort column, with ascending order (i.e. A to Z, which is the default). Then click Add Level to add a new sort column, and choose Total Sales with Largest to Smallest for the sort order.

Use Excel menu Data >> Filter
select arrow button on header row then select sort type as you wish.
Or you need more sort select like below picture.
Add level and select column which you would like to sort then click OK.
The result should be like this.

Related

How to give numbers to row that reset every time the value of another column changes?

this is probably a simple question, but I want to create row numbers based on the values in the column.
It would look like this:
1 | AAA
2 | AAA
3 | AAA
1 | BBB
2 | BBB
1 | CCC
2 | CCC
3 | CCC
4 | CCC
1 | DDD
2 | DDD
I don't really know how to word my question since my first language isn't english, but what would be the function or steps to take to achieve that?
The answer that I found from #BigBen is this:
=IF(A2=A1,B1+1,1)
https://superuser.com/questions/631644/count-the-number-of-sequential-duplicates-excel

How to sort and ignore spaces?

I'm trying to sort a file but I can't get the results I want.
I have this file :
742550111 aaa aaa aaa aaa aaa 2008 3 1 1
5816470687 aa a dissertation for the 933 2 2 2
Each field is separated by a tabulation, and I would like to sort on the second column.
When I try sort test.txt -t\t -k 2, the output is the same as in the file.
But the output I want to have is :
5816470687 aa a dissertation for the 933 2 2 2
742550111 aaa aaa aaa aaa aaa 2008 3 1 1
I think that's because sort ignores the spaces between the words.
So I tried with this command : LC_ALL=C sort test.txt -t\t -k 2, but it still doesn't work.
Do you have any ideas ?
Bash replaces $'\t' with a real tab:
LC_ALL=C sort file -t $'\t' -k 2
Output:
5816470687 aa a dissertation for the 933 2 2 2
742550111 aaa aaa aaa aaa aaa 2008 3 1 1

Trying to find clients that have ONLY bought one certain item in excel

I have two items codes 555 and 777 that are the same item (Pen). If they are the only items a customer has bought I would like to see just them. Example below
Name CustomerID Item Name Item # Desired Result
Bob 1 Tape 111
Bob 1 Tape 111
Bob 1 Pen 555
Greg 3 Pen 555 Check
Jim 4 Tape 111
Jim 4 Pen 555
Tom 7 Tape 111
Tom 7 Stapler 222
Jack 8 Pen 777 Check
Zach 9 Pen 555
Zach 9 Paper 333
Zach 9 Stapler 222
Zach 9 Tape 111
=IF(OR(AND(B1:B3,D2=555),AND(B1:B3,B2=777)),"Check","")
is what I have tried but it just marks any with 555 or 777.
use:
=IF(AND(OR(D2={555,777}),COUNTIF(B:B,B2)=1),"Check","")
If you know that the customers are sorted, you could try something like:
=IF(AND(OR(D2=555,D2=777),AND(B2<>B1,B2<>B3)),"Check","")
unless you also want to check customers who bought both 555 and 777.
AND(B1:B3,D2=555) probably isn't doing what you want. B1:B3 will always be 'true' (it's not an expression, its just a range), so that is only checking if D2=555

Mainframe Sort - Getting count based on field

My requirement is to get the count based on the field.
For example:
AAA 1234
AAA 111
...
AAA 112
BBB 123
BBB 123
...
BBB 333
CCC 333
Output should be:
AAA 2000
BBB 300
CCC 1
I am using the Sort card:
SORT FIELDS=(1,3,CH,A)
OUTFIL REMOVECC,NODETAIL,
SECTIONS=(1,3,TRAILER3=(1,3,X,COUNT=(M10,LENGTH=10)))
But I need the count to be left justified. Currently the count is displaying with leading spaces.
How can I make these count results left justified?

How to replace the character I want in a line

1 aaa bbb aaa
2 aaa ccccccccc aaa
3 aaa xx aaa
How to replace the second aaa to yyy for each line
1 aaa bbb yyy
2 aaa ccccccccc yyy
3 aaa xx yyy
Issuing the following command will solve your problem.
:%s/\(aaa.\{-}\)aaa/\1yyy/g
Another way would be with \zs and \ze, which mark the beginning and end of a match in a pattern. So you could do:
:%s/aaa.*\zsaaa\ze/yyy
In other words, find "aaa" followed by anything and then another "aaa", and replace that with "yyy".
If you have three "aaa"s on a line, this won't work, though, and you should use \{-} instead of *. (See :h non-greedy)

Resources