Loading

Showing Different Calculation for Sub-totals and Grand Totals in Tableau

Date de publication: May 29, 2025
Tâche

How to show a different calculation for Subtotals and Grand Totals in Tableau. For example, showing SUM([Sales]) in cell, but SUM([Profit]) in Sub-totals & SUM([Quantity]) in Grand Totals.

Étapes

Follow along with the Tableau attached packaged workbook to review the steps below.  The workbook can be found at the bottom of the article in the Attachments section.


Step 1 - Create a calculated field

  1. Select Analysis > Create calculated field
  2. Name the calculated field "New Totals"
  3. Enter the following formula and click OK
    IF WINDOW_COUNT(ATTR([Category]))=0 THEN SUM([Quantity])
    ELSEIF WINDOW_COUNT(ATTR([Category]))=3 THEN SUM([Profit])
    ELSE SUM([Sales])
    END

Build the view

  1. Drag Category and Sub-Category to Rows
  2. Drag the new calculated field to Text
  3. Click Analysis > TotalsShow Column Grand Totals
  4. Click Analysis > TotalsAdd All Subtotals

Important: The result of window_count depends on the data and the view, and such results will be effected by filters. We recommend using this workaround after sufficient testing.

Numéro d’article de la base de connaissances

001453768

Pièces jointes

Other Grand Total Example.twbx

2366 KB

 
Chargement
Salesforce Help | Article