Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
LukaIT
Contributor
Contributor

Variable definition in Expression

I have this simple Expression and my question is can I and how to make things simple?

Metroplex-1={'1'} needs to be changed to 2,3,4,5,6,7 in other expressions (I copy-paste it 6 times and then change '1' to '2' in the whole expression which is really painful and a waste of time.

Can I use Variable for [Metroplex-1] in Expression so that instead of changing 10 times I change Variable in Expression on one place and Expression is using it? or any other suggestions on how to make things a bit faster.

Thanks

My Expression:

(((Count({$<FleetBookAgreement={'Rental'},[Metroplex-1]={'1'}>}FleetBookAgreement)+
Count({$<FleetBookAgreement={'Booking'},resStatus_Name={'Active'},[Metroplex-1]={'1'}>}FleetBookAgreement))
-
Count({$<FleetBookAgreement={'Rental'},CountXto-={1},[Metroplex-1]={'1'}>}FleetBookAgreement))
-

((Count({$<FleetBookAgreement={'Rental'},res7day={'N'},[Metroplex-1]={'1'}>}FleetBookAgreement)+
Count({$<FleetBookAgreement={'Booking'},resStatus_Name={'Active'},res7day={'N'},[Metroplex-1]={'1'}>}FleetBookAgreement))
-
Count({$<FleetBookAgreement={'Rental'},CountXto-={1},res7day={'N'},[Metroplex-1]={'1'}>}FleetBookAgreement))

+
(Count({$<IgnoreOOS={'Y'},[Metroplex-1]={'1'}>}OOS)
-Count({$<IgnoreOOS={'Y'},res7day={'N'},[Metroplex-1]={'1'}>}OOS))
-Count({$<IgnoreOOS-={'Y'},res7day={'N'},OOSgroup={'Mirovanje'},[Metroplex-1]={'1'}>}OOS))


/
(
Count({$<TYPE={'FleetHistory'},PlanType-={'Defleeted'},Future={'N'},[Metroplex-1]={'1'}>}distinct XCarPlateno)+Sum({$<Future={'Y'},Xyear={$(vCurYear)},[Metroplex-1]={'1'}>}poKOM)+Count({$<Future={'Y'},[Metroplex-1]={'1'}>}distinct CarId)
+Count({$<Type={'OW'},Future={'Y'},[Metroplex-1]={'1'}>}OWplusId)
-
Count({$<Type={'OW'},Future={'Y'},[Metroplex-1]={'1'}>}OWminusId)

-Count({$<IgnoreOOS-={'Y'},Future={'Y'},OOSgroup={'Mirovanje'},[Metroplex-1]={'1'}>}OOS))

Labels (1)
5 Replies
marcus_sommer

It's not clear which number do you want to adjust - within the field or the field-value?

[Metroplex-1]={'1'}

LukaIT
Contributor
Contributor
Author

[Metroplex-1]={'1'}

[Metroplex-1]={'2'}... 

 

marcus_sommer

You may replace it with a variable which would change the call to:

[Metroplex-1]={$(myVar)}

An alternatively would be to use a field-selection for it. Most simple would be to provide the field [Metroplex-1] directly which would be the most natural way - the user just selects what's interesting. But you may also provide a not related field per island-table and then the call may look like:

[Metroplex-1] = p(MySelectionField)

LukaIT
Contributor
Contributor
Author

Hi Marcus,

could I define myVar in Expression? 

This is KPI and it has around 30 expressions in each group.
Each group has its own Metroplex 1,2,3,4... so instead of changing each expression, the Metroplex number 10-20 times I would like to change 1 variable on the top of the expression, and with it I won't need to edit 500-600 variables 🙂

Hoping you understand me

The user is not selecting anything, if needed they use filters but this is a KPI that is divided into 11 metroplexes so you can see each of them without filtering

 

Thanks

 

KPI-view.png

marcus_sommer

You may use parametrized variables, like:

myVar:
sum({< $1 = {$2}>} $3)

and calling them like:

$(myVar(Field1, ValueXYZ, Field2))

which could reduce the number of needed variables quite significantly.

But you will further need to adjust this variable-expression by each call. You are just minimizing the lengths of the expression which has benefits (easier to maintain) as well as disadvantages (loosing overview).

More simple and more performant would be to use table-charts instead of KPI objects. It won't provide this amount of layout-capabilities but is also able to display the essential information.