Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
MPkg
Contributor III
Contributor III

How to create a Line Chart formula and Fields in IF statement in Qlik Sense

I need to create a line chart where:

- Dimension is Time (0-10s, step 1s)

- Measure is  Velocity (changes in time).

I have two tables of these two values, in the first table, I have the Time_1 and Velocity_1 fields, and in the second table Time_2 and Velocity_2 fields.

By selecting the value, in a separate table, in the Vehicle field (Vehicle_1 or Vehicle_2) the chart should automatically change.

The problem is that when I include two fields in the chart formula the chart gets in an endless loading state and does not render.

 

The formula in the chart is:

for Dimension:

 

if(GetSelectedCount([Vehicle])=1,If([Vehicle]='Vehicle_1',Time_1,If([Vehicle]='Vehicle_2',Time_2,0)))

 

for Measure:

 

if(GetSelectedCount([Vehicle])=1,If([Vehicle]='Vehicle_1',Velocity_1,If([Vehicle]='Vehicle_2',Velocity_2,0)))

 

 

Note:

The next formula works:

 

if(GetSelectedCount([Vehicle])=1,If([Vehicle]='Vehicle_1',Velocity_1,If([Vehicle]='Vehicle_2',5,0)))

 

I tried nonworking formula in Multi KPI like this:

 

if(GetSelectedCount([Vehicle])=1,If([Vehicle]='Vehicle_1','Velocity_1',If([Vehicle]='Vehicle_2','Velocity_2',0)))

 

 and with strings, everything works nicely, but when I use Fields instead of strings there is a bug.

Labels (1)
11 Replies
MPkg
Contributor III
Contributor III
Author

Great! Thank you very much!

This expression with minstring is very helpful, I was just looking for something to automatically select the last remaining choice in a field.

To be honest I was making a mistake that I tried to implement set expression in a Dimension, and this did not work. Set expression of course only works with Measures.

Thank you very much and have a nice day!

stevedark
Partner Ambassador/MVP
Partner Ambassador/MVP

No worries. Note that you can use set analysis in a dimension, but you need to have an aggr in there also, on the same field. So to have only field values starting with A in the dimension of a chart you would have:

aggr(maxstring({1<Dim*={"A*"}>}Dim), Dim)

Just in case the need ever arises! 🙂

Steve