Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

joeybird
Contributor II

Dynamic formatting of a bar chart

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

1 Solution

Accepted Solutions
Employee
Employee

Re: Dynamic formatting of a bar chart

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

2 Replies
Employee
Employee

Re: Dynamic formatting of a bar chart

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

joeybird
Contributor II

Re: Dynamic formatting of a bar chart

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