BASE DE CONNAISSANCES

Showing Different Calculation for Sub-totals and Grand Totals


Date de publication : 18 Sep 2019
Date de dernière modification : 15 Sep 2023

Question

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

Environnement

Tableau Desktop

Réponse

Follow along with the attached packaged workbook to review the steps below.  The workbook can be found to the right of this text 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.
Cet article vous a-t-il permis de résoudre le problème ?