Reem
Reem

Reputation: 59

Need to display count of rows per a value of a column

Worksheet

Hi, I have a Tableau worksheet that displays a list of members (Member name and some other columns), It's required to add a column to contain the number of members for each due date (e.g. 1/1/2022 -> 1, 1/5/2022 -> 1, 1/9/2022 -> 1, 1/12/2022 -> 8 )

I tried to add a calculated field (CountForEachDueDate) that has a LOD syntax {INCLUDE [DueDate] : Count([MemberName])} , I add the calculated field to the view as a measure Sum(CountForEachDueDate) I get 1 in each record, any advices?

Upvotes: 0

Views: 2106

Answers (1)

Alex Blakemore
Alex Blakemore

Reputation: 11921

Broken down into baby steps, assuming the mark type is set to Automatic (or Text)

  1. Remove Member Name from the Rows shelf
  2. Add Member Name to the Label or Text Shelf (it will default to being treated as dimension)
  3. Right click on Member Name on the Marks Card and change it a Measure in this case, selecting the aggregation function COUNTD - which stands for Count Distinct

You should see a row for each date that appears in the data, and the number of different member names that have data for each date in the view.

If you poke around on the various menus, you can find a way to pad out the dates to list a row for each date, even if there are no records for it. Either under the Analysis menu, or by looking at the context menu for the Date field.

Finally, you can speed your work and combine the 3 steps above into 1 action by holding down the right mouse button as you drag the Member Name field from Rows to Label or Text. You’ll then be prompted to choose how you want to treat the Member Name field on the new shelf.

Key to this working is to understand that fields are not permanently treated as dimensions or measures. The setting in the data pane is simply the default, and can be changed on each shelf. That allows you to treat a field like Member Name as a dimension in some contexts, and as measure in others.

Upvotes: 0

Related Questions