3 Replies Latest reply on Jun 7, 2017 6:38 AM by Esther Twain

    Effect of ATTR

    Esther Twain

      Hello community,

       

       

      Please refer to the screenshot. For some reason the .twbx is saving too large of a file.

      I want to color the line chart that comes before a Reference Date, given by a parameter, and put on the Color marks. This is already done by:

      ref line with Attr.PNG

       

       

      ATTR(IF [Order Date] < [Reference Date] THEN "Before"

      ELSE "After"

      END)

       

      similar to

       

      IF [Order Date] < [Reference Date] THEN "Before"

      ELSE "After"

      END

       

      However if we put the ATTR as like:

       

      IF ATTR([Order Date]) < ATTR([Reference Date]) THEN "Before"

      ELSE "After"

      END

       

      This no longer works.

       

      Can someone please walk me through as why each formula works for the intended purpose (what is the effect of the ATTR)? And why the last one doesn't?

       

      Thanks,

       

       

      Esther

        • 1. Re: Effect of ATTR
          Zhouyi Zhang

          Hi, Esther

           

          The reason why you code below doesn't work, because in your screen shot, you put month in your column, which means, in this portion, the order date is not unique.

           

          IF ATTR([Order Date]) < ATTR([Reference Date]) THEN "Before"

          ELSE "After"

          END

           

          If you look at the description of ATTR(), it should be a single value. In this case, your code should work if you change your month to date

           

          Here is my result after changing month to day

           

          Hope this could help you have a better understand.

          Please let me know if you have question.

           

          ZZ

          • 2. Re: Effect of ATTR
            Wilson Po

            If the [Reference Date] is a parameter, i think the error might just be related to the fact that you cannot leverage an ATTR() agg on parameters. There's no formal definition on why this is, but I suspect it has to do with the fact that parameters are not really non-aggregates or aggregates;  you can actually compare a parameter to either type in a calculation and it seems to work fine.  You might give this a go:

            IF ATTR([Order Date]) < [Reference Date] THEN "Before"

            ELSE "After"

            END

             

            It shouldn't give you a "Cannot mix Aggregate and Non Aggregate"  error.

            1 of 1 people found this helpful
            • 3. Re: Effect of ATTR
              Esther Twain

              Hi Zhouyi,

               

              Indeed it helped! Thanks I've never have gotten through the real meaning of Attribute... But you just explained to me now

               

              Esther