Skip to main content

I have created some table calculations to try and get the change between an items value in its last update and now. I have the following metrics/calcs:

1) Cost Price Just the price of an item

2) Previous Cost Price, which is a look up value

if ISNULL(LOOKUP(SUM([Cost Price Value]),-1)) then 0 ELSE LOOKUP(SUM([Cost Price Value]),-1) END

3) Current Value: To properly calculate the difference between the previous value and current (bypassing missing values) I needed to to turn Cost Price into a look up value as well

if ISNULL(LOOKUP(SUM([Cost Price Value]),0)) then 0 ELSE LOOKUP(SUM([Cost Price Value]),0) END

4) Cost Price Change: The difference between Previous and Current Value (Again all the complications of isnull etc were the only way to get it to calculatte properly

IF ISNULL([1:Current Value]) then 0 else IFNULL([1:Current Value],0) END - (IF ISNULL([1:Previous Cost Price Value]) then 0 else [1:Previous Cost Price Value] end)

All of these are in my table and calculated using table across (as they are based on the Created date of the Item update)

All of the above calcs do as expected and even the Subtotals work well. HOWEVER, I also need to have two columns, one showing only negative price changes from formual 4 above and one showing only +ve price changes from formula 4.

I do this with a simple if:

IF [1:Cost Price Change] <= 0 then [1:Cost Price Change] else 0 END (And just change the operator for postive).

At a row by row level it works correctly However

issue lies in that with the subtotals the Negative Price Change column shows the total as 0 and the positive calculates all values (+ and - even though in the column the -ve's show as 0s).

 

This not only breaks the subtotal but when I want to roll up to one hierarchy above to see these totals it doesn't total up correctly.

 

Attached is also a screen shot of my table. My calcs in the table (as described above) are Price Change, Negative and Positive Change.

Note the subtotal of Price change working Correctly but the subtotals of +ve and -ve not. For aggregating these subtotals, it would be at the object level

 

Sub Totals in Tableau Desktop Table Calcs

답변 2개
  1. 2025년 7월 9일 오전 12:33

    Hi Sebastian,

     

    To put it simply, unless Tableau is working with the lowest granularity of the data, its not going to do subtotals well. The great news is Jonathan Drummey put together a massive guide on this a few years ago, but its put in a way that I could never express in a forums post - check this out - https://drawingwithnumbers.artisart.org/customizing-grand-totals-part-1/

     

    Once you get to the end of the 3 part series, there's probably not much more to know about how it works.

     

    HTH

     

    Peter

0/9000