0
votes

I am trying to create a calculated field like the below.

but it gives me an error on aggregate and non aggregate values.

Can someone help?

 if (COUNTD([Category])=1 then [Sub-Category]
else [Category] END

Note: I am using the super store data. So when a user selects a filter in the quick filter for category, I was hoping that the countd becomes one and shows sub category as rows in the table instead of category.

1
DID you use or try ATTR ?Chetan_Vasudevan
ATTR on the column name like category just gives a * when dragged into columns or rows.Nat85
FIXED : COUNTD ?Chetan_Vasudevan
It still gives the same error on aggregate valuesNat85
Is there a way to find the distinct count that can be used in the calculated fields to select the column?Nat85

1 Answers

0
votes

You could use a sheet selector approach to get this effect. The idea is to create a calculated field that outputs a column to be used a the filter to select the sheet.

  1. First create a calculated field as follows:

    { FIXED : if COUNTD([Category]) = 1 then 'Sub Category' elseif countd([Category]) > 1 then 'Category' END}

  2. Now create two worksheets one broken down by category and the other my sub category.
  3. Add your Category filter to both worksheets and set to a context filter.
  4. Drag your calculated field column onto the filter pane as well. For the Category worksheet select the filter to Category and vice versa for the sub category worksheet. Hint you can manually add the value or edit your category filter to show the relevant value for each worksheet
  5. Drag both worksheets into a dashboard and format so the worksheets behave appropriately https://community.tableau.com/thread/132957
    1. Tada! A dashboard where the axis will change depending on what you have selected.