Count the number of times each value is in a column
Count the number of times each value is in a column
I have a datatable that has a column called 'Category'. There may be hundreds of rows. The category column only has 4 possible categories.
I want to count how many times each category is present across the whole table and store them in separate variables.
So if 'Repair' is in the column 100 times, then $repair_count = 100;
if 'Service' is in the column 50 times, then $service_count = 50;
I want to do this without having the user filter/search the column. I want to display the counts outside the table.
I've search to no avail for a clue!
This question has an accepted answers - jump to answer
Answers
This is called "binning" - the alphabet search shows one possible way to do it. Basically you need to loop over the data and just have a counter for each option.
Allan