Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Pilegaard
Contributor

Setting variable with an expression in an expression

Hi, 

I'm using Google Timeline Extension and want the user to be able  to sort by different dates (columns in my dataset)

If I put the following expression into my lead column as Sort by Expression it works fine: 

=rank([Timeline Dates.ASORT.autoCalendar.Date])

Then I figured, if I create a button for each date type I want to sort by and then use the button expression to set a variable with the above expression then I will have a dynamic sort which can be triggered by the user. However I cannot get it to work 😞

I defined my variable in the button as follows:

button1: set $(vSort) = rank([Timeline Dates.ASORT.autoCalendar.Date])

button2: set $(vSort) = rank([Timeline Dates.BSORT.autoCalendar.Date])

...

button8: set $(vSort) = rank([Timeline Dates.CSORT.autoCalendar.Date])

 

Then I entered the variable vSort into the Sort by Expression in the Google Timeline Extension, but the data is not sorted when pushing the buttons.

Can anyone tell me what I'm doing wrong? Or even better how to get the button sort to work?

Br,

Keld

Labels (2)
1 Solution

Accepted Solutions
treysmithdev
Partner Ambassador

Can you provide a picture of your settings?

A couple suggestions:

  1. Make sure you are setting the variable 'vSort' to the value, not the expanded version '$(vSort)'.
  2. Create a KPI object with your sort expression: ='$(vSort)'. Does this look correct to you?
    1. If it does, then the issue is with the expression evaluation in the sort expression.
    2. If it does not, the issue is with setting the variable vSort.
  3. Do not include the equal sign '=' in your variable value. 
    1. vSort should be: rank([Timeline Dates.BSORT.autoCalendar.Date])
    2. Sort Expression should be: =$(vSort)
    3. This will evaluate to: =rank([Timeline Dates.BSORT.autoCalendar.Date])
    4. The other way would be ==rank([Timeline Dates.BSORT.autoCalendar.Date]), which is not valid.

 

 

Blog: WhereClause   Twitter: @treysmithdev

View solution in original post

2 Replies
treysmithdev
Partner Ambassador

Can you provide a picture of your settings?

A couple suggestions:

  1. Make sure you are setting the variable 'vSort' to the value, not the expanded version '$(vSort)'.
  2. Create a KPI object with your sort expression: ='$(vSort)'. Does this look correct to you?
    1. If it does, then the issue is with the expression evaluation in the sort expression.
    2. If it does not, the issue is with setting the variable vSort.
  3. Do not include the equal sign '=' in your variable value. 
    1. vSort should be: rank([Timeline Dates.BSORT.autoCalendar.Date])
    2. Sort Expression should be: =$(vSort)
    3. This will evaluate to: =rank([Timeline Dates.BSORT.autoCalendar.Date])
    4. The other way would be ==rank([Timeline Dates.BSORT.autoCalendar.Date]), which is not valid.

 

 

Blog: WhereClause   Twitter: @treysmithdev
Pilegaard
Contributor
Author

Hi Trey,

Thank you for your reply. It helped me to figure out the problem is to set the variable value, because when I hard code the 'rank([Timeline Dates.BSORT.autoCalendar.Date])' in the variable definition it works and the chart is sorted by this column.

I'm using a Variable Extension (https://github.com/erikwett/qsVariable) to set the variable value. I just checked the version of this extension in our system and it is very old, so I will ask for it to be updated to the newst version and hope that this would help. 

Just for your info. I did not succed in getting any values but 0 out in the KPI or text box when inserting the variable.

Br,

Keld