2 Replies Latest reply: Apr 24, 2015 10:20 AM by Joanna Seldon RSS

    Dynamic formatting of a bar chart

    Joanna Seldon

      Hiya

       

      Qlik Sense

       

      is there a way of dynamically changing a format of a bar chart depending on its values....

       

      some rows of data are for percentages

       

      apples 75%

       

      workers 1008  and some are just number values

       

      when a bar chart is used its formatted for percentages...when the selected apples

       

      however when someone selected workers...its showing in percentage (it would)

       

      is there a way to dynamically change the formatting if a "Format"column was added with eg... number or percentage?

       

      could I use expression formatting code similar to this ? and if yes... is this correct way to do it???

       

      IF(([TargetValue] AND [Format] = 'Percentage')

      OR ([TargetValue] AND [Format] = 'Number'), %(), Number())

       

       

      or can a small drop down be added? users can use on the sheet of the app and just select format percentage or number? this will dynamically change the formatting of the bar chart?

       

      any ideas please?


      Kind Regards

       

      Joeybird

        • Re: Dynamic formatting of a bar chart
          Jonathan Poole

          Hi - i did get this to work. 

           

          1. Build a 2 row (or more) data island table in the data model with each row determining a 'format code'

           

          Format:

          load

            if(RowNo()=1,'Percentage','Integer') as Format

          AutoGenerate 2;   

           

          2. Build a variable to determine the numeric format based on the selection:

           

          set vFormat='if(Only(Format)=' & chr(39) & 'Integer' & chr(39) &',' &chr(39)& '#,##0' & chr(39) & ',' & chr(39) & '#,##0%' & chr(39) & ')';

           

           

          3. Invoke the variable in the 2nd argument of the num() function to dynamically determine the format.

           

          change measure expression from:

           

          sum(Sales)

           

          to:

           

          num( sum(Sales), $(= chr(39) & $(=$(vFormat)) & chr(39)) )

           

          and leave format to 'auto

            • Re: Dynamic formatting of a bar chart
              Joanna Seldon

              Hiya

               

              this code worked amazing, however it does not like below

               

              load

                if(RowNo()=1,'Percentage','Integer') as Format

              AutoGenerate 2; 

               

              all I did was create the extra column called format, and said if the row was Percentage or Integer

               

              then used all the rest of the instructions and hay presto.

               

              Thanks so much x

               

              Kind Regards

               

              Joeybird