5 Replies Latest reply on Oct 18, 2018 6:56 AM by Mahfooj Khan

    Dividing in a calculated field

    Terence Mervis

      I have a Transaction table listing orders and returns. The column describing the nature of each transaction (either order or return) is called [Type]. The column [Quantity] lists the amount of units for each transaction. I want to create a calculated field (called Return%), calculating the returns as a percentage of orders. I used the following formula - SUM(CASE [Type] WHEN 'Refund' THEN [Quantity] ELSE 0 END) / SUM(CASE [Type] WHEN 'Order' THEN [Quantity] ELSE 0 END).

      It's returning zero percent. I'm displaying this metric as a Label on a graph, with Date on the horizontal axis (aggregated by month) and Quantity on the vertical axis.

      Column Shelf - Month(Date)

      Row Shelf - SUM(Quantity)

      Color Mark- [Type]

      Label Mark - AGG(Return%)

      Attached is a similar graph from mock data. Although the calculated field in this case is a meaningless number, the idea is the same.

      Tableau Desktop 2018.2.2

      Any guidance would be appreciated.