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

Alternate state to take most default selections, but not all

Hello, 

I've discovered Alternate States and am working on implementing them in a tab that will allow the user to select two distinct periods to compare.  This year for example, the users often want to compare the week with the week +1 of last year to line up the weeks (leap year...). 

I have two multi-boxes that allow the user to select  year(s), year-week(s), date(s)

leenlart_1-1619105184092.png

The pivot will then allow comparing the data over the two selected periods A, and B.  My alternate states are called [Période A] and [Période B]

My problem is the current year and month are selected by default on opening the app, so I'd like my pivot table to ignore the year, month, or even selected dates from the default state but include any other selection.

I've tried the following syntaxes : 

1./ Sum( {[Période A]*$<TYPE_CALENDRIER={'N'}, ORIGIN={'FACTURES'} >} VOLUME )  => this gives 0 if the current year <> state year etc.  

2./ Sum( {[Période A]*$<TYPE_CALENDRIER={'N'}, ORIGIN={'FACTURES'}, YEAR, YEAR_WEEK, DATE_JOUR>} VOLUME )   => this gives a huge number I can't explain (the sum of all dates maybe?)

3./ Sum( {<TYPE_CALENDRIER={'N'}, ORIGIN={'FACTURES'}, YEAR=[Période A]::YEAR, YEAR_WEEK=[Période A]::YEAR_WEEK, DATE_JOUR=[Période A]::DATE_JOUR>} VOLUME )  => this gives 0 if the current year <> state year etc.  

The only way I can get the chart to work correctly is to clear the selected date fields on entering the sheet, but I don't like this cheater work-around, as the user will then have to re-select the dates on leaving the sheet...

What am I missing here?  A lot I'm sure....  but if you have any ideas for this problem I would really appreciate it!

Labels (1)
3 Replies
jwjackso
Specialist III
Specialist III

Perhaps using the P()  function will help.

 

Sum( {<TYPE_CALENDRIER={'N'}, ORIGIN={'FACTURES'}, YEAR=P({[Période A]}YEAR), YEAR_WEEK=P({[Période A]}YEAR_WEEK), DATE_JOUR=P({[Période A]}DATE_JOUR)>} VOLUME )

 

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Your #2 looks about right to me, that's the technique I typically use.

https://qlikviewcookbook.com/2016/07/alt-states-merged-selections-tip/

Hard to say what's wrong without seeing the data model.

-Rob

leenlart
Creator
Creator
Author

So I tried the P() function but that doesn't work either.

I minimized things down, so attached is my app, maybe there is something in the data model ?