Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Priya_on_Surface
Partner - Contributor
Partner - Contributor

Qlik sense: Conditions on defined script variables

Dear Members,

I tried to search a lot for this but couldn't find the answer anywhere, apologies if this has been asked already. I am fairly new to Qlik sense.

  • I I have a variable defined in the script as v_avg_days_for_objects.
  • I use a KPI chart on the dashboard and call the variable as $(v_avg_days_for_objects).  Quite straightforward till here.
  • Now I want to have a filter on this variable for only those objects that are new, so a condition like:   {<object_type={"New"}>}

However I do not know the syntax, I don't want to have to create separate variables for different conditions. Any help is much appreciated.

 

Thank you.

4 Replies
Wlad_Masi
Employee
Employee

Hello there,

What is the expression of your variable?
If it is for ex EX: avg(Objects)
You would have to change it to: =$(avg( {<object_type={"New"}>}Objects))
To help users find verified answers, please don't forget to mark a correct resolution or answer to your problem or question as correct.
SergeyMak
Partner Ambassador
Partner Ambassador

Hi,

It all depends on how your v_avg_days_for_objects is defined.

Let's say the original expression is Count([Days]). To be able to pass the parameter you'll have to redefine it as

Count({$<DummyField, '$1'>}[Days])

in this case you can use your variable in the following way:

$(v_avg_days_for_objects(object_type={"New"}))

This is a simplified approach, which allows you to pass only one parameter and one filter, but it can be enhanced to accept as many parameters as you want.

 

Regards,

Sergey

Regards,
Sergey
Priya_on_Surface
Partner - Contributor
Partner - Contributor
Author

hi,

I want to call the variable as it is with an additional condition, so no functions used.

 

Thanks.

kuba_michalik
Partner - Specialist
Partner - Specialist

Undoable. Filters (aka set analysis) are part of the expression. You can write your expression specifically in a way that make them (somewhat) customizable on the fly as Sergey suggested, but other than that you just need to write a new separate expression (and keep it in a new separate variable if you want) for the KPI object.

If this is about keeping consistency between the formulas (e.g. it's already long and complicated and you just want to add one extra filter) then you could consider splitting the formula in smaller blocks in separate variables and combining them as needed.