Skip to main content

Section Calculated Fields

We’ve done a little bit of practice creating calculated fields in Tableau, but if we do slightly more complicated things, the syntax is different than what we’re used to in Excel.

Example 8.2.

Download the Tableau Workbook below that includes data from the 2023 National Survey of Children’s Health. Here is a link to information about the dataset: Link to information about variables
 1 
www2.census.gov/programs-surveys/nsch/technical-documentation/codebook/2023-NSCH-Screener-Variable-List.pdf
Let’s look at the proportion of children who need or currently take medication, which is labeled “C_K2Q10”. We want to find the number of responses with a “1” and divide by the total number of responses.
We’ve practiced doing things like this in Excel, but Tableau is a little different.
Use ChatGPT or Copilot and ask “If I have a variable labeled C_K2Q10, how would I calculate the proportion of responses that were a “1” in a calculated field in Tableau?”
Check to see if you get the answer below, and then create this calculated field in Tableau.
Answer.
SUM(IF [C K2Q10]=1 THEN 1 ELSE 0 END)/COUNT([C K2Q10])

Example 8.3.

Continue working with the Tableau Workbook from the previous problem that includes data from the 2023 National Survey of Children’s Health, and now create a calculated field for the proportion of children who need or get special therapy such as physical, occupational, or speech therapy. (This is in “C_K2Q19”.)
Answer.
SUM(IF [C K2Q19]=1 THEN 1 ELSE 0 END)/COUNT([C K2Q19])

Example 8.4.

Use the calculated fields you found in the last two exercises and make a table containing those values.