SOLVED

How to count multiple values in a cell

Copper Contributor

Hello,

 

This is the first time I post!

 

I need to do the following. I have a dataset and one of the fields is made up of cells that can have multiple values. For example the below. We have cells that contain zero, one or multiple names and I would need to count those names like in a pivot table. These names are separated by an "enter". In the example below I put the desired output.

 

 

 20192018
Class 1John
Mary
Mary
Joseph
Matthew
Class 2Theresa
Anthony
Matthew
Margaret
Class 3John
Theresa
Theresa
Margaret

 

Desired output:

 

 Number of Classes
Person20192018
John20
Theresa21

 

Thanks in advance!

 

7 Replies
best response confirmed by Ugarte335 (Copper Contributor)
Solution

@Ugarte335 I used Powerquery to massage your data as you can see in the attached file. From the green table it'll be easy to create your pivottable report. You can also feed the result of the query into the pivottable directly without using the intermediate green table of course.

Thank you, this was much easier than I expected!

PowerQuery to the rescue!

@Ugarte335 

I modified the Query to transform the data in the desired format which you showed in the description.

Please refer to the attached.

Name Count By Year.jpg

 

 

 

@Ugarte335 

Just for the collection, here is a bit another version of query, resulting table is in brown.

Thank you so much for your help@Sergei Baklan

 

However, I tried with the data downloaded from the provider and it does not recognise it as new line for some reason. The delimiter with the data I provided first was a new line and it was recognised by power query.

 

Now it doesn't. I have attached the spreadsheet for your convenience.

 

Thanks

@Ugarte335 

It works with your file, please checked attached. I converted the data into the table to simplify, by that doesn't matter. You may use range or query sheet from another file.

image.png

Generated script is

let
    Source = Excel.CurrentWorkbook(){[Name="tblNames"]}[Content],
    #"Added Custom" = Table.AddColumn(
        Source,
        "Name",
        each Text.Split([Names],"#(lf)")
    ),
    #"Expanded Custom" = Table.ExpandListColumn(
        #"Added Custom",
        "Name"
    ),
    #"Removed Other Columns" = Table.SelectColumns(
        #"Expanded Custom",
        {"Country", "Name"}
    )
in
    #"Removed Other Columns"
1 best response

Accepted Solutions
best response confirmed by Ugarte335 (Copper Contributor)
Solution

@Ugarte335 I used Powerquery to massage your data as you can see in the attached file. From the green table it'll be easy to create your pivottable report. You can also feed the result of the query into the pivottable directly without using the intermediate green table of course.

View solution in original post