How do I find the difference between the two columns in Tableau?

  • Tableau FAQs
  • December 13, 2018
Get Started Transforming Your Data in Snowflake

I have two columns that I am trying to find the difference from rather than the total. Can someone help me set up the formula?

To compare data from two fields and calculate the difference, you can use the LOOKUP function. Assuming you have data in fields for 2020 and 2019, then you could use the following expression to find the difference:

 

LOOKUP(

    SUM([OrderQty]),

    LAST()) -

LOOKUP(SUM([OrderQty]),

    FIRST())

LOOKUP( Returns the value of the expression in a target row, specified as a relative offset from the current row. Use FIRST() + n and LAST() – n as part of your offset definition for a target relative to the first/last rows in the partition. If offset is omitted, the row to compare to can be set on the field menu. This function returns NULL if the target row cannot be determined.

    SUM([OrderQty]), – here we specify data aggregation

    LAST()) –  here we specify the offset


Up Next:

Read How to create a triple dual axis on a Tableau worksheet chart?