
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Intervalmatch Count Open Items
I've been messing with this for 7+ days and I think I'm close, but could use a boost over the fence please:
Here are the details:
1 table: id, created_when, validated_when + various other fields.
master calendar/island.
OBJECTIVE:
Combo chart with 3 elements:
Date as dimension
Line 1: Items created that day
Line 2: Items closed that day
...so far so good. I created some flags, works fine.
Bars across the bottom, I'd like to show total OPEN(outstanding) items on that day.
Suffice to say, if an item is created on 2/1, closed on 2/10, then from 2/1-2/09 it would be among the counted 'open'.
OpenValidatedDate:
Load
id,
id as OVID,
created_when as CreatedDate,
created_when as Date,
1 as Flag_Created,
Resident rfi;
Concatenate (OpenValidatedDate)
Load
id,
id as OVID,
validated_when as ValidatedDate,
validated_when as Date,
1 as Flag_ValidatedDate
Resident rfi
where exists (validated_when);
IntervalMatch:
IntervalMatch (Date)
Left join
Load distinct CreatedDate, ValidatedDate
resident OpenValidatedDate;
- « Previous Replies
-
- 1
- 2
- Next Replies »
Accepted Solutions


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Maybe I have looked at the wrong charts, but I can't see that you are using ReferenceDate as dimension in you combo chart. The solution I suggested will not create the correct open count if you are using a different date field that is only linked by ID to the DateLink table.
I see that you also want to show the sum of created and validated IDs in your chart. To be able to do this easily, create flags for this in the DateLink table:
DateRange:
LOAD ID, created, If(Len(Trim(validated)),validated,Today()) as validated;
LOAD ID,
SetDateYear(Date#(created,'M/D'),2016) as created,
SetDateYear(Date#(validated,'M/D'),2016) as validated
INLINE [
ID, created, validated
1, 2/1, 2/5
2, 2/3, 2/7
3, 2/3,
4, 2/5, 2/6
5, 2/6,
];
LinkTable:
LOAD ID, Date(created+iterno()-1) as ReferenceDate,
If(iterno()=1, 1,0) as CreatedFlag,
If(Date(created+iterno()-1) = validated, 1,0) as ValidatedFlag
Resident DateRange
WHILE created+iterno()-1 <= validated;
Then link your master calendar to the ReferenceDate, use ReferenceDate as dimension and as expressions
=Count(DISTINCT ID)
=Sum(CreatedFlag)
=Sum(ValidatedFlag)


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Have a look at this blog post:
Creating Reference Dates for Intervals
use the reference date as dimension in your charts, then
=Count(DISTINCT id)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the quick response, but I don't think I must have explained myself well. I tried that and it's not quite what I'm looking for.
I'll try again:
ID created validated
1 2/1 2/5
2 2/3 2/7
3 2/3 -
4 2/5 2/6
5 2/6 -
I want a chart that shows all dates as the dimension (Master Calendar?) and a count of open items as such:
Date Open items
2/1 1
2/2 1
2/3 3
2/4 3
2/5 3 (id 4 added, id 1 validated - ids 2, 3, 4 open)
2/6 3 (id 5 added, id 4 validated - ids 2, 3, 5 open)
Basically, a running net total of open items per day of the year.
Hope that makes sense?
Thanks so much for the quick reply.


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Right, I believe that's exactely what's demonstrated in HICs blog post.
If you apply the recipe with the WHILE loop, your table (you would need to fill in an end date for validated without value, like today())
ID created validated
1 2/1 2/5
2 2/3 2/7
3 2/3 -
4 2/5 2/6
5 2/6 -
will transform to an additional table with fields
ID, Date
with one record per ID and date within date range between created and validated.
Then you create a master calendar and link to Date field.
Done.
Use Date as dimension and
=Count(DISTINCT ID)
as count for the open IDs per Date.
You can use calendar fields to drill up to week, month, year as needed.
BTW, an Intervalmatch LOAD prefix matching your master calendar to the date ranges (again, with end dates added for open intervals) will basically create the same, but I think the solution with the WHILE loop is much more simple.
Best
Stefan


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Basically, it looks like
DateRange:
LOAD ID, created, If(Len(Trim(validated)),validated,Today()) as validated;
LOAD ID,
SetDateYear(Date#(created,'M/D'),2016) as created,
SetDateYear(Date#(validated,'M/D'),2016) as validated
INLINE [
ID, created, validated
1, 2/1, 2/5
2, 2/3, 2/7
3, 2/3,
4, 2/5, 2/6
5, 2/6,
];
LinkTable:
LOAD ID, Date(created+iterno()-1) as Date
Resident DateRange
WHILE created+iterno()-1 <= validated;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks so much Stefan,
I think we're close - I appreciate the help more than I can express
Few questions I've come up with (as always!):
Can you tell me what the purpose of the SetDateYear statements are for?
I wonder why the 2 Load statements? I notice if I remove the 2nd 'Load', it fails, so I left it in.
id is used in a variety of places, would this need to be a separate id (id as otherid) as it's a new table?
Here's what I have with actual fieldnames. Unfortunately, I'm getting an error that's stumping me. error is in the bold area and reads:
Field not found - <created_when>: LOAD id, SetDateYear(Date#(created_when,'M/D'),2016) as created, SetDateYear(Date#(validated_when,'M/D'),2016) as validated resident rfi
created_when is the accurate fieldname and I seem to just be missing the problem.
rfi is the original datasource so I assumed the actual load would be a resident load of that?
DateRange:
LOAD
id,
created_when,
If(Len(Trim(validated_when)), validated_when, Today()) as validated;
LOAD
id,
SetDateYear(Date#(created_when,'M/D'),2016) as created,
SetDateYear(Date#(validated_when,'M/D'),2016) as validated
resident rfi;
LinkTable:
LOAD id, Date(created_when+iterno()-1) as Date
Resident DateRange
WHILE created_when+iterno()-1 <= validated;
thoughts?
....EDIT....
I made a few changes which resulted in a synthetic key, then more which relieved it.
The first thing I did was to comment out the 2nd load statement. That ALMOST got us there. The data was VERY close to being accurate, though there were areas where it wasn't as I tested it against the data source.
I know we're close . . . Here are my iterations:
CURRENT::
DateRange:
LOAD
id as DateRangeID,
created_when,
If(Len(Trim(validated_when)), validated_when, Today()) as validated
// LOAD
// id,
// SetDateYear(Date#(created_when,'M/D'),2016) as created,
// SetDateYear(Date#(validated_when,'M/D'),2016) as validated
resident rfi;
LinkTable:
LOAD
DateRangeID,
DateRangeID as LinkID,
Date(created_when+iterno()-1) as LinkCreatedDate
Resident DateRange
WHILE created_when+iterno()-1 <= validated;
------------------------------------------------------------------------------------------------------------
PREVIOUS:
DateRange:
LOAD
id,
created_when,
If(Len(Trim(validated_when)), validated_when, Today()) as validated
// LOAD
// id,
// SetDateYear(Date#(created_when,'M/D'),2016) as created,
// SetDateYear(Date#(validated_when,'M/D'),2016) as validated
resident rfi;
LinkTable:
LOAD
id,
Date(created_when+iterno()-1) as Date
Resident DateRange
WHILE created_when+iterno()-1 <= validated;
I can see t his will get me where I'm going, just almost there.
Thanks again!


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your sample data misses year information in the date fields, so I think if you just interpret month and date, Qlik will assume 1900 as year for your sample data.
But to generate the accurate date range (especially when we replace missing end dates with today()!), we should explicitely state the year of your records.
SetDateYear() is just a function that changes / setting the year for a date value. Have a look at the Date & Time functions in Qlik, there are a lot of them and there are different approaches to interpret the correct date from your text values.
You need to take care to adapt the Date#() interpretation function to your input field format (or if they come in as numbers, just format them as date).
See also
You can do the transformation also in 1 LOAD step (without the preceding LOAD), which should perform better, but I tend to write it using the preceding LOAD for clarity.
If the field created_when is not found, have you maybe renamed the field or qualified the table in the LOAD that created rfi table? Have a look at the table viewer to see how the complete field name looks like.
I would also suggest that you do the date transformation in the original rfi table LOAD (or don't forget to DROP rfi table to avoid having a mostly duplicate table in your data model).
If you are running into synthetic keys, then probably because other tables show same field names, assumingly Date, that link to both new rfi table and DateLink table?
To help you more, you would need to post at least a screen shot of your data model.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok, thanks a lot.
Here's where we are today:
DateRange:
LOAD
id,
created_when as rangecreated,
If(Len(Trim(validated_when)), validated_when, Today()) as rangevalidated
resident rfi;
LinkTable:
LOAD
id,
Date(rangecreated+iterno()-1) as ReferenceDate
Resident DateRange
WHILE rangecreated+iterno()-1 <= rangevalidated;
My dates do have year - just didn't post that, so I removed that part.
As you see, I changed the fieldnames to make them unique, which has eliminated all synthetic errors.
No code issues currently, script loads fine, and when I count(distinct id), it ALMOST works!
The other weird issue is, when I use Date as my dimension (which is originally from the MasterCalendar, it only populates dates where events occur, not all of them now. interesting behavior.
The problem I'm seeing is that in comparing the results to the actual data, it's just off in some places by a small amount.
I've attached a screenshot of my data model for you, also a spreadsheet showing what Qlik Sense is displaying (#N/A means no data displayed), and what the actual values should be.
Again, SO close and thank you!


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You need to use the ReferenceDate as the dimension when you want to count the open IDs.
You may want to create a master calendar also for the ReferenceDate, if you want to drill up to lower granular calendar fields.
See also
Tutorial - Using Common Date Dimensions and Shared Calendars
If this does not fix your issue, then could you maybe post a small sample QVD?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I read the tutorial and chased the rabbit hole into canonical dates, multiple master calendars - just not sure which direction is correct. Changing to using the ReferenceDate as the dimension made things worse.
I'm attaching my qvf so you can peek at what I have. The actual graph is on the RFI Regional Summary tab, the sandbox I'm using is Sandbox2
Thank you

- « Previous Replies
-
- 1
- 2
- Next Replies »