Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
A couple months ago I found an article that allowed me to give the users control over the selecting the date range for and followed the suggestions in this post and outside of a minor issue with the back button it has been working fine.
However, I have a new requirement to implement a comparative view and I’m not successfully incorporating this into the alternate states the comparative view has to use.
In the stripped-down scrambled version of the application I’m attaching you can see how the comparative view isn’t quite working as I hoped it would.
Navigate to the ‘Compare’ tab. Make sure all selections are clear. Pick August 1, 2013 in the ‘Group A’ start date (top-left) and September 12, 2013 for ‘Group A’ end date (bottom-left). We’re left with a full-blue bar for August and a half a blue bar for September which is what we want as far as that goes.
You’ll notice that under ‘Group B’ you can only pick the Start Date. This is because the requirements state that ‘Group B’ End Date needs to be calculated by taking the number of days between Group A’s start and end date and add those same number of days to whatever Group B’s start date. This also works fine.
The problem is with the chart. Given that there is a approximately 1.5 months between the dates in Group A there should be approximately 1.5 months worth of bars rendered on the chart. Pick various start dates for Group B and you can see that the chart does not correctly calculate. However, if you pick the same Group B start date twice it will show up correctly.
In the attached file you’ll find (amongst others) six variables: vStartDate, vEndDate, vStartDateGroupA, vEndDateGroupA, vStartDateGroupB and vEndDateGroupB.
These variables are acted upon in various places:
Settings -> Document Properties -> Triggers -> Document Event Triggers -> OnAnySelect
Settings -> Document Properties -> Triggers -> Variable Event Triggers -> {all variables listed above}
{Each calendar control} -> Properties -> General -> Min Value & Max Value
Thank you for your consideration in assisting me with this vexing issue.
Dave,
Alternate states is not needed for the variables or the calendars. I think that is why you were getting unexpected results. See attached for a simplified working example.
-Josh
What is happening is QlikView is calculating the values of vStartDateGroupB and vEndDateGroupB in parallel. So when determining the vEndDateGroupB, it is using your 'old' value of vStartDateGroupB. Thus on the second time selected the 'old' value is the 'correct' value so you get the result you are looking for.
Change the definition of vEndDateGroupB to be the expression you are using in to set the value in the trigger on vStartDateGroupB and remove action(s) that sets vEndDateGroupB.
Regards,
Josh
PS glad you found my video helpful.
Thanks Josh --
I understand what you're saying and it makes sense but I'm afraid the I must not be implementing your suggestion correctly. I've removed the actions that updated vEndDateGroupB and attempted various ways to use the expression as the variable's definition. For one example, in the load script I have:
LET vEndDateGroupB = Date(vStartDateGroupB + (Date(vEndDateGroupA, 'M/D/YYYY') - Date(vStartDateGroupA, 'M/D/YYYY')), 'M/D/YYYY');
However, it simply sets the variable to the last date of the data set and leaves it there no matter what I select for dates in the other calendar controls.
And yes, I found your video very helpful. The customers particularly like how the date will reflect the range of their other selections.
Dave
Hi Dave,
I played around with it for a while and found I was unable to manually change the vEndDateGroupB. I suspect there is an action somewhere that is change the variable back but couldn't find it. I would suggest you try creating a new QVW that only does this date action and see if that works. That will prove out if the approach is wrong or if there is a setting in the current QVW that is overriding our efforts.
-Josh
I really appreciate you taking the time to work with me on this. I'll work on getting a new app together to see if we can demonstrate this functionality without any possible conflicts from other aspects of the app.
I was struck with a thought that I hand't mentioned. I can't imagine why this would have anything to do with it but just in case -- one of the things I did to try and make this work was to copy the trans_posted_date field into their own dates (GrpA_trans_posted_date and GrpB_trans_posted_date) so each group's dates aren't fighting with each other. Do you think this is this an undesirable approach that might be complicating the solution?
Dave
As requested here is a new QVW with nothing but the comparative tab and the controls needed. I should forewarn you that this one works less than the original version. Faced with the decision to get this one to work better vs. putting up a version that has the minimal alterations I went with the later. I was afraid I'd introduce too much extraneous code and violate the spirit of what we were hoping to accomplish so I put in what I thought were the least amount of triggers and code required even if it doesn't do much of anything. I hope this helps. I'll be taking the version I have and try to get it to work but thought this version should be the one to post in the meantime.
Dave
Dave,
Alternate states is not needed for the variables or the calendars. I think that is why you were getting unexpected results. See attached for a simplified working example.
-Josh
That is brilliant. Thank you so much.
Happy to help!