Announcements
cancel
Showing results for
Did you mean:
Contributor III

## Dimension selection depending on a Filter state

Hi,

I want to have  a dimension to be changed on my Line chart depending on a selection in a 'Period' field. For example if 'Today' is selected I want to have hour granularity, if 'This year' is selected I want to have month granularity. I have appropriate fields.

So I am trying to use this expression for my dimension field:

= if(Period = 'Today', Hour,
(if(Period = 'Yesterday', Hour,
(if(Period = 'This week', Weekday,
(if(Period = 'This month', Day,
(if(Period = 'This year', Month, Day)
)
)
)
)
)
)
)
)

But, it doesn't work.

What I am missing or doing wrong?

Labels (3)

• ### filter

1 Solution

Accepted Solutions
Contributor III
Author

I have got a solution to my problem.

We need to create a set of variables with field names assigned:

vHour = CanonicalHour

vDay = CanonicalDay

vMonth = CanonicalMonth

etc.

After we should create a variable with condutional selection:

vDimension = if(GetFieldSelections(Period) = 'This month', vDay,
if(GetFieldSelections(Period) = 'This year', vMonth, vHour   // and so on
)
)

And finally we write in our dimension expression:

\$(=\$(vDimension))

Voila, it works)

3 Replies
Specialist II

@Andrei_Faibich Did you try creating Drill down Dimension?

First you need to create a Drill Down Master Item by Adding all the fields required.

Use the same Drill Down Dimension in the Dimension of line chart and Filter Pane

https://help.qlik.com/en-US/sense/September2017/Subsystems/Hub/Content/Dimensions/create-drill-down-...

If this resolves your issue, please like and accept it as a solution.

Contributor III
Author

Thanks for the prompt reply, but

I need this logic to be hardcoded, user selects only values from the field 'Period'!

Contributor III
Author

I have got a solution to my problem.

We need to create a set of variables with field names assigned:

vHour = CanonicalHour

vDay = CanonicalDay

vMonth = CanonicalMonth

etc.

After we should create a variable with condutional selection:

vDimension = if(GetFieldSelections(Period) = 'This month', vDay,
if(GetFieldSelections(Period) = 'This year', vMonth, vHour   // and so on
)
)

And finally we write in our dimension expression:

\$(=\$(vDimension))

Voila, it works)