How can I concatenate values in an Excel pivot, as opposed to summing or counting - excel

Say I have the following data:
Col1 Col2
------------
Bob Green
Bob Green
Bob Green
Chris Blue
Chris Blue
Chris Red
Dave Blue
Dave Green
Dave Red
A default Pivot Table in Excel would yield:
Col1 Col2
------------
Bob Green
Chris Blue
Red
Dave Blue
Green
Red
Is there any way to concatenate on Col2 (specifically, with separators), so I end up with this?:
Col1 Col2
------------
Bob Green
Chris Blue,Red
Dave Blue,Green,Red

What you want is not possible from a PivotTable. However, if Bob is in A2 a formula in C2 like:
=IF(A1=A2,C1&", "&B2,B2)
and another in D2 of:
=A2=A3
both copied down to suit, may serve if you "fill in the gaps" (either in the PT or with Go To Special, Blanks, =, Up, Ctrl+Enter) then select all, Copy, Paste Special, Values over the top and filter to delete rows showing TRUE.
TEXTJOIN is now available on some versions.

Related

append to existing values if condition is true

I want to compare the values row by row from sheet1-colors with sheet2-darkcolors
if they are both matching append the row values d and e to the fruits column in sheet 1
basically
sheet1 colors |blue |=== sheet2 darkcolors |blue| ----> fruits+yummy+yuicy
sheet1
colors
fruits
blue
bananay
red
apple
green
kiwi
sheet2
darkcolors
d
e
blue
yummy
juicy
black
tummy
fruicy
green
tummy
goosy
result
colors
fruits
blue
banana+yummy+juicy
red
apple
green
kiwi+tummy+goosy
I tried using `IF` combined with `XLOOKUP` but could not get it running together
Try-
=IFERROR(TEXTJOIN("+",TRUE,B2,INDEX(TRANSPOSE(Sheet2!$B$2:$C$4),,MATCH(A2,Sheet2!A2:A4,0))),B2)

Count how many distinct values (or get list of distinct values) in a filtered column

Is there a way to count the number of distinct values in a filtered column in Excel?
Using the formula at https://exceljet.net/formula/count-unique-values-in-a-range-with-countif I can count the number of distinct values in a range, but when that range has been filtered with an auto-filter I still get the unfiltered count.
For example:
A B
1 Scarf Blue
2 Hat Red
3 Gloves Green
4 Coat Blue
5 Balloon Red
6 Shoes Blue
Counting unique values in B with =SUMPRODUCT((B1:B6<>"") / COUNTIF(B1:B6,B1:B6 & "")) should return 3 as the distinct values are Red, Green and Blue.
If I auto filter Column B to just select Red items, the resulting table will look like:
A B
2 Hat Red
5 Balloon Red
In this case the number of distinct values retuned should be 1. But the formula above still returns 3.
The formula should also cope with multiple selections in the auto-filter, so for example filtering for Blue and Green should result in the following table:
A B
1 Scarf Blue
3 Gloves Green
4 Coat Blue
6 Shoes Blue
From which the formula should return 2 (Blue, Green).
Finally, if I am filtering on column A rather than B, the formula should still work. So If I am only interested in Hat, Scarf and Coat, filtering column A for these values would result in:
A B
1 Scarf Blue
2 Hat Red
4 Coat Blue
From which the formula should return 2.
(I'm using Excel 2013 and need to do this in a formula rather than using VBA etc)
I also found this page on office.com which I thought might help, but alas I can't get it to work for me.
This reference shows how you can exclude hidden rows using AGGREGATE
Excluding hidden rows with AGGREGATE
You can then use a standard way of counting unique values like this
Counting unique values with FREQUENCY
So if you were counting values in column B, you would need a helper column (say C) containing
=IF(AGGREGATE(3,5,B2),B2,"")
Then plug in the form of count unique that ignores empty cells
=SUM(IF(FREQUENCY(IF(LEN(C2:C10)>0,MATCH(C2:C10,C2:C10,0),""), IF(LEN(C2:C10)>0,MATCH(C2:C10,C2:C10,0),""))>0,1))
Or your formula if you prefer
=SUMPRODUCT((C2:C10<>"") / COUNTIF(C2:C10,C2:C10 & ""))

Excel sorting and data matching

I have a large excel sheet with many columns. I do not want to sort columns A - X. Column Z needs to be sorted so the values in column Z = values in column A (A55=Z55).
Column Y is related to column Z (Y22 related to Z22). So column Y and Z must maintain there relationship before and after the sort. Example Data:
Column A: A123, A456, A556, B234
Column Y: red, yellow, pink, green
Column Z: A556, A456, B234.
How do I sort column Z (and Y)?
Easiest Way:
My Array:
Add Column:
New Array(s):
Sort A smallest to largest (important!):
Sort Z smallest to largest:
Delete Temp Column and voila:
If you are fine with adding columns, then instead of directly sorting Y and Z we can essentially create 2 new columns that are the sorted values according to column A.
So if your data looks like this:
A ... Y Z
------------------------
A123 red A556
A456 yellow A456
A556 pink B234
B234 green A123
We can create this:
A ... Y Z AA AB
---------------------------------------
A123 red A556 A123 green
A456 yellow A456 A456 yellow
A556 pink B234 A556 red
B234 green A123 B234 pink
The formula for column AA would be a straight cell reference to column A:
=A1, =A2, =A3, etc.
The formula for column AB would be a simple index/match combination:
=INDEX(Y:Y,MATCH(AA1,Z:Z,0))
So it would look like this:
A ... Y Z AA AB
---------------------------------------------------------------
A123 red A556 =A1 =INDEX(Y:Y,MATCH(AA1,Z:Z,0))
A456 yellow A456 =A2 =INDEX(Y:Y,MATCH(AA2,Z:Z,0))
A556 pink B234 =A3 =INDEX(Y:Y,MATCH(AA3,Z:Z,0))
B234 green A123 =A4 =INDEX(Y:Y,MATCH(AA4,Z:Z,0))

Excel Bring back Unique Record and description

I have a table in excel that I am bringing in from Access.
I can get a unique Name from the list, but I don't know how to bring the description in the format below.
This is how the table in excel looks like:
Name Description
John Black
John Blue
John Black
Mary Green
Mary Blue
Jim Yellow
Jim Yellow
Jim Black
I want it to look like this so I'll have two field name and description will be both unique
Name Description
John Black, Blue
Mary Green, Blue
Jim Yellow, Black
thanks!
First Remove Duplicates. If Name is in A1, in C2:
=IF(A1=A2,C1&", "&B2,B2)
in D2:
=A2=A3
Copy both down to suit. Select all, Copy, Paste Special, Values over the top, filter on ColumnD to select TRUE, delete selection, delete ColumnD and ColumnB.

Count of unique values in multiple columns

What I need is probably best described in an example. It's a bit different from the group functionality and also the PivotTable in Excel, because I want it to show up in the data row itself (and not off to the side or below, etc.). Given a table like:
Fruit Color Farmer
Banana Yellow Smith
Banana Yellow Smith
Apple Yellow James
Apple Yellow James
Apple Green Smith
Banana Yellow James
I want to take the first two columns and give the count of rows that have the same values (regardless of the values in the other columns). So for my example, I would get:
Fruit Color Count Farmer
Banana Yellow 3 Smith
Banana Yellow 3 Smith
Apple Yellow 2 James
Apple Yellow 2 James
Apple Green 1 Smith
Banana Yellow 3 James
My preference would be an Excel formula (or even a built in function) as opposed to VBA.
Assuming Fruit is in A1, please try in C2 (having made room for it):
=COUNTIFS(A:A,A2,B:B,B2)
and copy down to suit.

Resources