Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Data Works for AI is here - Join the discussion and enter to win a pair of Qlik kicks: Join the Conversation!
cancel
Showing results for 
Search instead for 
Did you mean: 
OdieW
Contributor III
Contributor III

When a bookmark is chosen, how can I make a secondary KPI show a different value than the bookmark would normally show

I have a calendar with a daily date field and a bookmark field with labels to classify each of the dates. So today's date is labeled Today, yesterday is labeled yesterday, All days in July(Current Month) are labeled Current month, all days from June are labeled previous month. This is dynamic so it changes as the day, months, quarters, years roll over. There are a few that are like two weeks ago or others that won't have an "opposite"

My app defaults to the current month bookmark. I have 3 KPIs all with a primary and secondary KPI. These KPIs show counts, the main KPI is a count filtered/set analysis to a specific request type, no date filtering so it will always show the count based on the selected bookmark or all time if no bookmark is selected. The secondary KPI is a count of the same request type but shows the count from previous month regardless of what bookmark is selected.

 

What I am trying to do is have the secondary KPI show the "opposite" of the selected bookmark. So if current month bookmark is selected the secondary KPI shows previous month. If the selected bookmark is Previous year then I want the secondary KPI to show the count for current year.

 

What is the best way to go about this? I believe multiple if statements will work but it makes for some long ugly code. Any better options?

Labels (1)
1 Solution

Accepted Solutions
marcus_sommer
MVP
MVP

I think I wouldn't use bookmarks else direct selections of the wanted periods which are specified within The As-Of Table - Qlik Community - 1466130 which enables the selection (and/or using them as dimensions) of any overlapping dimension-values.

The period-information might be not just strings like MTD or YTD else dual() values like suggested from @Or - whereby the as-of-table mustn't contain only two fields else the relation of current period-part to the previous one might be specified within n fields and may also contain any further categorising of the period-stuff, like yearly/monthly or fix/rolling or whatever.  

View solution in original post

4 Replies
Or
MVP
MVP

First of all, bookmarks aren't "selected". Activating a bookmark may make several selections on fields, but afaik there's no indication that a bookmark was chosen after the fact (you can work around this by having the bookmark toggle a variable, but even then any other selection will presumably break that? There's probably some creative way to do that).

With that out of the way, answering a question with a question - how would the Qlik engine "know" what the opposite is? If you can spell out the logic in a formula, you can use that formula to achieve. 

If there's no way to know at the moment, consider rephrasing your field, e.g. by assigning numeric values to your presets and then having the positive number be "current" and the negative "previous" with the same number (2 and -2, for example), at which  point you can just use sign() or *-1 to flip them around. 

OdieW
Contributor III
Contributor III
Author

When I say selected I don't mean in a qlik sense fashion, more so that the user of the app selects what bookmark they want to use from a list/filter pane of bookmarks.

I did forget to mention that I used the following code in my load script for my calendar, which already had date and bookmark(label). The below code adds an additional column to that table that creates the current to previous logic. I made an update to my post saying I can accomplish what I want with multiple if statements. It works to do what I want it appears. I haven't yet tested it with what happens when other bookmarks are selected, so it could still break but it works when only using the bookmark filter pane.If this works completely then I can use it, it just seems like there should be a more elegant option than telling qlik if this then that over and over again.

Date(
If(Bookmark = 'Today', Date - 1,
If(Bookmark = 'Yesterday', Date + 1,
If(Bookmark = 'Current Week', Date - 7,
If(Bookmark = 'Previous Week', Date + 7,
If(Bookmark = 'Current Month', AddMonths(Date, -1),
If(Bookmark = 'Previous Month', AddMonths(Date, 1),
If(Bookmark = 'Current Quarter', AddMonths(Date, -3),
If(Bookmark = 'Previous Quarter', AddMonths(Date, 3),
If(Bookmark = 'Current Year', AddYears(Date, -1),
If(Bookmark = 'Previous Year', AddYears(Date, 1),
Null()
))))))))))) AS OppositeDate

Or
MVP
MVP

As I said, assigning a numeric value to each one (you can use Dual()) and having "Current" be positive and "Previous" be negative should let you just use (Bookmark*-1). This would definitely be more elegant, though the if() solution seems good enough here. 

marcus_sommer
MVP
MVP

I think I wouldn't use bookmarks else direct selections of the wanted periods which are specified within The As-Of Table - Qlik Community - 1466130 which enables the selection (and/or using them as dimensions) of any overlapping dimension-values.

The period-information might be not just strings like MTD or YTD else dual() values like suggested from @Or - whereby the as-of-table mustn't contain only two fields else the relation of current period-part to the previous one might be specified within n fields and may also contain any further categorising of the period-stuff, like yearly/monthly or fix/rolling or whatever.