Count distinct values dimensions

In this use case, you want to get the distinct number of product names that have been reported on during January 2023.

Customer Journey Analytics

To report on a distinct count of product names, you set up a calculated metric in Customer Journey Analytics, with Title Product Name (Count Distinct) and External Id product_name_count_distinct.

Customer Journey Analytics Product Name (Distincr Count) calculated metric

You then can use that metric in an example Count Distinct Dimension Values panel for the use case:

Customer Journey Analytics Distinct Count Values

BI tools
note prerequisites
PREREQUISITES
Ensure you have validated a successful connection, can list data views, and use a data view for the BI tool for which you want to try out this use case.
tabs
Power BI Desktop
  1. To ensure the date range apply to all visualizations, drag and drop daterangeday from the Data pane on to Filters on this page.

    1. Select the daterangeday is (All) from Filters on this page.
    2. Select Advanced filtering as the Filter type.
    3. Define the filter to Show items when the value is on or after 1/1/2023 And is before 2/1/2023.
    4. Select Apply filter.
  2. In the Data pane:

    1. Select datarangeday.
    2. Select sum cm_product_name_count_distinct, which is the calculated metric defined in Customer Journey Analytics.
  3. To modify the vertical bar chart to a Table, ensure you have the chart selected and select Table from the Visualizations pane.

    Your Power BI Desktop should look like below.

    Power BI Desktop Multiple Count Distinct table

  4. Select the table visualization. From the context menu, select Copy > Copy visual.

  5. Paste the visualization using ctrl-v. The exact copy of the visualization overlaps the original one. Move it to the right in the report area.

  6. To modify the copied visualization from a table to a card, select Card from Visualizations.

    Your Power BI Desktop should look like below.

    Power BI Desktop Multiple Count Distinct table

Alternatively, you can use the count distinct functionality from Power BI.

  1. Select the product_name dimension.

  2. Apply the Count (Distinct) function on the product_name dimension in Columns.

    Power BI Count Distinct

Tableau Desktop
  1. Select the Sheet 1 tab at the bottom to switch from Data source. In the Sheet 1 view:

    1. Drag the Daterange entry from the Tables list in the Data pane and drop the entry onto the Filters shelf.

    2. In the Filter Field [Daterange] dialog, select Range of Dates and select Next >.

    3. In the Filter [Daterange] dialog, select Range of dates, and select 01/01/2023 - 31/1/2023. Select Apply and OK.

    4. Drag Cm Product Name Count Distinct to Rows. The value changes to SUM(Cm Product Name Count Distinct). This field is the calculated metric that you have defined in Customer Journey Analytics.

    5. Drag Daterangeday and drop next to Columns. Select Daterangeday and from the drop-down menu select Day.

    6. To modify the lines visualization to a table, select Text Table from Show Me.

    7. Select Swap Rows and Columns from the toolbar.

    8. Select Fit Width from the Fit drop-down menu.

      Your Tableau Desktop should look like below.

      Tableau Desktop Multiple Dimension Ranked Filter

  2. Select Duplicate from the Sheet 1 tab context menu to create a second sheet.

  3. Select Rename from the Sheet 1 tab context menu to rename the sheet to Data.

  4. Select Rename from the Sheet 1 (2) tab context menu to rename the sheet to Card.

  5. Ensure you have selected the Card view.

  6. Select DAY(Daterangeday) and from the drop-down menu select Month. The value changes to MONTH(Daterangeday).

  7. Select SUM(Cm Product Name Count Distinct) in Marks and from the drop-down menu select Format.

  8. To change the font size, in the Format SUM(CM Product Name Count Distinct) pane, select Font within Default and select 72 for the font size.

  9. To align the number, select Automatic next to Alignment and set Horizontal to centered.

  10. To use whole numbers, select 123.456 next to Numbers and select Number (Custom). Set Decimal places to 0.

    Your Tableau Desktop should look like below.

    Tableau Desktop Multiple Dimension Ranked Filter

  11. Select New Dashboard tab button (at the bottom) to create a new Dashboard 1 view. In the Dashboard 1 view:

    1. Drag and drop the Card sheet from the Sheets shelf onto the Dashboard 1 view that reads Drop sheets here.
    2. Drag and drop the Data sheet from the Sheets shelf underneath the Card sheet on the Dashboard 1 view.

    Your Dashboard 1 view should look like below.

    Tableau Desktop Dashboard 1

Alternatively, you can use the count distinct functionality from Tableau Desktop.

  1. Use Product Name instead of Cm Product Name Count Distinct.

  2. Apply Measure > Count (Distinct) on Product Name in Marks.

    Tableau Count Distinct

Looker
  1. In the Explore interface of Looker, ensure you do have a clean setup. If not, select Setting Remove fields and filters.

  2. Select + Filter underneath Filters.

  3. In the Add Filter dialog:

    1. Select ‣ Cc Data View
    2. From the list of fields, select ‣ Daterange Date then Daterange Date.
      Looker filter
  4. Specify the Cc Data View Daterange Date filter as is in range 2023/01/01 until (before) 2023/02/01.

  5. From the ‣ Cc Data View section in the left rail:

    1. Select Daterange Date, then Date.
    2. Select Aggregate ‣ Count Distinct from the ⋮ More context menu on Product Name.
      Looker Product Name Context menu
  6. Select Run.

  7. Select ‣ Visualization and select 6︎⃣ from the toolbar to display a Single value visualization.

You should see a visualization and table similar as shown below.

Looker count distinct

Jupyter Notebook
  1. Enter the following statements in a new cell.

    code language-none
    data = %sql SELECT COUNT(DISTINCT(product_name)) AS `Product Name` \
       FROM cc_data_view \
       WHERE daterange BETWEEN '2023-01-01' AND '2023-02-01';
    display(data)
    
  2. Execute the cell. You should see output similar to the screenshot below.

    Jupyter Notebook Results

RStudio
  1. Enter the following statements between ```{r} and ``` in a new chunk.

    code language-r
    ## Count Distinct
    df <- dv %>%
       filter(daterange >= "2023-01-01" & daterange < "2023-02-01") %>%
       summarise(product_name_count_distinct = n_distinct(product_name))
    print(df)
    
  2. Run the chunk. You should see output similar to the screenshot below.

    RStudio Results

recommendation-more-help
080e5213-7aa2-40d6-9dba-18945e892f79