3 Replies Latest reply on May 8, 2012 3:47 PM by Tracy Rodgers

    trailing spaces in a string

    ernesto debeaumarchais

      I'm trying to put the dates in a calendar view.  The thing is I would like the data to be centered in the box as opposed to right justified.  See the first picture below.

      I thought I'd be able to put some trailing spaces at the end,. after the "Cenus" data value, but it doesn't work.  I have to put a character like a "." at the end of the spaces or tableau just trims off all the spaces.  I tried using CHAR(), SPACE(), setting up a calculated field and referencing that, etc.

       

      This is my calculated field:

      "["+str(MIN(DAY(CensusDate)))+ "]

       

      " +
      str(sum(Census)) + "     "  ([THIS GETS IGNORED])
      +"
      "

      I tried changing it to use SPACE():

      "["+str(MIN(DAY(CensusDate)))+ "]

       

      " +
      str(sum(Census)) + space(10)
      +"
      "

      But then I get this error: Tableau Data Engine Error: 4: PrimitiveExp::MakePrimitive: map_concat_usr8_col_usr2_val

       

      I would think this should be simple, but it seems not to be.  Any ideas?

      calendar.png

      What I'm looking for is something like this

      "["+str(MIN(DAY(CensusDate)))+ "]

       

      " +
      str(sum(Census)) + "              ."
      +"
      "

      But without the stupid "." at the end:

       

      calendar2.png

        • 1. Re: trailing spaces in a string
          Tracy Rodgers

          Hi Ernesto,

           

          Which version are you using? When I used the above calculation, there was no need for the period at the end. Also, does the Center justify work?center justified.png

          -Tracy

          • 2. Re: trailing spaces in a string
            ernesto debeaumarchais

            Professional 7.0. 

             

            I can center it, but what I was aiming for was what I had in my second picture, where the date is in the top right corner and the data is in the center, so it looks more like a regular desktop calendar.  And there's a clearer distinction between the date and data:

            calendar2.png

            I am unable to get the trailing spaces after the data when I have it this way.  Tableau trims them unless I put some character like the "." at the end.  Are you able to get the spaces without putting a "." at the end?  If yes, can you post the example?

             

            I just kind of changed it around so that the fields are left justified instead:

            "["+str(MIN(DAY(CensusDate)))+ "]

             

            " + "              " +
            str(sum(Census))
            +"
            "

             

            calendar3.png

            Which is fine, I was trying to match something existing that looked the other way.  Plus now I'm just curious if there is a way to pad out the end of a string.

            • 3. Re: trailing spaces in a string
              Tracy Rodgers

              Hi Ernesto,

               

              I see what you are talking about now, and I was getting very frustrated as well. However, I think I found a solution. Change the alignment to Middle Center like in my previous post. Then, edit the calculation so the spaces are at the beginning, similar to the following:

               

              "                 ["+str(MIN(DAY(CensusDate)))+ "]

               

              " +

              str(sum(Census))

               

              Hope this gets you what you're looking for!

               

              -Tracy