LibreOffice: count distinct values from column

Solution 1:

A spreadsheet cannot do it as easily as with SQL, but here are two solutions.

Method 1 - Pivot Table

Make sure the first row of the column contains a label, for example Color. In the next column, set the label to Count. Enter a count of 1 for all colors.

Color  Count
red    1
green  1
red    1

Then, select the two columns and go to Data -> Pivot Table -> Create. Drag Color to Row Fields, and drag Count to Data Fields.

pivot table

Method 2 - Filter

  1. Copy the column data, and paste into column A of a new sheet.
  2. Go to Data -> More Filters -> Standard Filter.
  3. Change Field Name to - none -. Expand Options and check No duplicates. Press OK.
  4. In B1, enter the formula =COUNTIF($Sheet1.G1:G100,"="&A1). Change "G" to the column you used on Sheet 1.
  5. Drag the formula down.

Links for getting distinct values are at https://stackoverflow.com/a/38286032/5100564.