3 Replies Latest reply on Oct 7, 2018 11:14 AM by Michel Caissie

    LOD with Strings

    andre riley

      Hello Community,

       

      I need help with a calculation that essentially returns a string of the unique attributes of a call. In the simple data set below, the calculated field (labeled offersOnCall) will return the view pictured. The intent is to quantify the likelihood that sales reps will offer a specific offer type when presented with a specific set of choices.

       

      DATA SET

      call id, offer type

      123, upgrade

      125, xsell

      123, additional

      125, ugrade

      125, additional

       

      OUTPUT

      call id, offersOnCall

      123, upgrade additional

      125, xsell upgrade additional

        • 1. Re: LOD with Strings
          Michel Caissie

          Andre,

           

          You can use the previous_value function to accomplish this

          TRIM( ATTR( [Offer Type] + ' ') + PREVIOUS_VALUE('') )  restart computing on every ID

           

          Next add a filter last() = 0    to keep the last row

           

          Michel

          • 2. Re: LOD with Strings
            andre riley

            Thanks for that Micheal. Can you help me understand though, what is the point of the LAST() calc? I get everything except that, even when viewing it in context. Why should it matter whether we're looking at the last or the first row given the table calc specifies that it should restart for every ID?

            • 3. Re: LOD with Strings
              Michel Caissie

              Andre,

               

              If you look at the ValidateData  sheet,  you see that the concat calculation returns  it's value  of the previous row,  concatenated with the Offer Type of the current row.  So the final string that you are looking for is displayed on the last ID row.  And the  last() = 0  returns true on that row.

               

              Now the FinalView sheet  is a duplicate of the ValidateData sheet,  where the Offer Type dimension is hidden (right-click blue pill, unselect Show Header) . Remember that we need to keep  Offer Type in the view in order to be able to compute the previous_value.

              And the goal of the  last() = 0 calculation, is to use it as a filter and keep the true values, in order to hide from the view the rows that are needed for the calculation,  but we don't want the user to see.

               

              It may seems confusing,  since you filter out the first rows,  how come the concat calculation still works.  In Tableau  all table calculations are computed before table calculation filters are applied. And both  previous_value()  and last()   are table calculations. So when the last() = 0  filter is applied,  the concat  calculation have already been computed.