Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I am struggling with how to use AUTOGENERATE to fill in the gaps within my data model. My data consist of events that occur along with the event_type, hospital, and department. When I create a run sum of events by month, there are no data for some months after filters are applied. This causes a bar or combo chart summarizing events to skip the month in which there were no events for the selection.
Here is some example data. My initial load is actually from a file but I provided an inline load for example purposes.
[EVENTS]:
Load
*
Inline [
Event_Type, Event_Date, Hospital, Department,
A, 2/4/2019, HOSPITAL A, SURGICAL
B, 3/3/2019, HOSPITAL B, ICU
A, 1/10/2019, HOSPITAL C, MEDICAL
B, 3/8/2019, HOSPITAL B, ICU
C, 2/28/2019, HOSPITAL A, OR
C, 1/20/2019, HOSPITAL A, OR
C, 2/15/2019, HOSPITAL A, OR
A, 3/19/2019, HOSPITAL A, ICU
B, 3/18/2019, HOSPITAL B, ORTHO
];
[Events_Summary]:
LOAD
Event_Type,
Event_Date,
Hospital,
Department,
1 as Event_Count
Resident [EVENTS];
DROP TABLE [EVENTS];
I would like to use the load script to autogenerate a value of 0 (zero) Event_Count for each unique combination of year-month, event_type, Hospital and Department. That way there will always be at least a monthly SUM(Event_Count) of 0 regardless of the selection along event_type, hospital or department.
Oh, my bad! I got the NEXTs in the wrong order. Try the script below, I've even added logic for excluding zero transactions for combinations that already exists with.
[EVENTS]: Load * Inline [ Event_Type, Event_Date, Hospital, Department, A, 2/4/2019, HOSPITAL A, SURGICAL B, 3/3/2019, HOSPITAL B, ICU A, 1/10/2019, HOSPITAL C, MEDICAL B, 3/8/2019, HOSPITAL B, ICU C, 2/28/2019, HOSPITAL A, OR C, 1/20/2019, HOSPITAL A, OR C, 2/15/2019, HOSPITAL A, OR A, 3/19/2019, HOSPITAL A, ICU B, 3/18/2019, HOSPITAL B, ORTHO ]; [Events_Summary]: LOAD Event_Type, Event_Date, Hospital, Department, 1 as Event_Count, Hash256(Event_Type, Event_Date, Hospital, Department) AS %EventID Resident [EVENTS]; DROP TABLE [EVENTS]; //Looping throug every possible combination of Type, Date, Hospital and Department
for each vEvent_Type in fieldvaluelist('Event_Type') For each vEvent_Date in fieldvaluelist('Event_Date') For each vHospital in fieldvaluelist('Hospital') For each vDepartment in fieldvaluelist('Department') Concatenate (Events_Summary) LOAD Hash256('$(vEvent_Type)','$(vEvent_Date)' , '$(vHospital)', '$(vDepartment)') AS %EventID, '$(vEvent_Type)' as Event_Type, '$(vEvent_Date)' as Event_Date, '$(vHospital)' as Hospital, '$(vDepartment)' as Department, 0 as Event_Count Autogenerate 1 WHERE
//Excluding combinations that already exists in the table. NOT EXISTS(%EventID, Hash256('$(vEvent_Type)','$(vEvent_Date)', '$(vHospital)', '$(vDepartment)')) ; Next vDepartment Next vHospital Next vEvent_Date Next vEvent_Type DROP FIELD %EventID //You don't need this column in the datamodel
did you try below
https://community.qlik.com/t5/Qlik-Design-Blog/Autogenerate-Your-Data/ba-p/1465273
I am attaching a QVF file to help with the troubleshooting. My goal is the get the combo chart bars to show zero regardless of the filter pane selections.
Oh, my bad! I got the NEXTs in the wrong order. Try the script below, I've even added logic for excluding zero transactions for combinations that already exists with.
[EVENTS]: Load * Inline [ Event_Type, Event_Date, Hospital, Department, A, 2/4/2019, HOSPITAL A, SURGICAL B, 3/3/2019, HOSPITAL B, ICU A, 1/10/2019, HOSPITAL C, MEDICAL B, 3/8/2019, HOSPITAL B, ICU C, 2/28/2019, HOSPITAL A, OR C, 1/20/2019, HOSPITAL A, OR C, 2/15/2019, HOSPITAL A, OR A, 3/19/2019, HOSPITAL A, ICU B, 3/18/2019, HOSPITAL B, ORTHO ]; [Events_Summary]: LOAD Event_Type, Event_Date, Hospital, Department, 1 as Event_Count, Hash256(Event_Type, Event_Date, Hospital, Department) AS %EventID Resident [EVENTS]; DROP TABLE [EVENTS]; //Looping throug every possible combination of Type, Date, Hospital and Department
for each vEvent_Type in fieldvaluelist('Event_Type') For each vEvent_Date in fieldvaluelist('Event_Date') For each vHospital in fieldvaluelist('Hospital') For each vDepartment in fieldvaluelist('Department') Concatenate (Events_Summary) LOAD Hash256('$(vEvent_Type)','$(vEvent_Date)' , '$(vHospital)', '$(vDepartment)') AS %EventID, '$(vEvent_Type)' as Event_Type, '$(vEvent_Date)' as Event_Date, '$(vHospital)' as Hospital, '$(vDepartment)' as Department, 0 as Event_Count Autogenerate 1 WHERE
//Excluding combinations that already exists in the table. NOT EXISTS(%EventID, Hash256('$(vEvent_Type)','$(vEvent_Date)', '$(vHospital)', '$(vDepartment)')) ; Next vDepartment Next vHospital Next vEvent_Date Next vEvent_Type DROP FIELD %EventID //You don't need this column in the datamodel