Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Counting ALL values by Month on a fixed chart dimension

Hello.

The problem I have relates to fixing the dimension on a chart for all the months of the financial year (April 10 -March 11). In the scenario I want to count ALL the clients that were considered to be in Effective Treatment in that month. The issue is that the x-axis is controlled by a table that explicitly states the financial Month/Year and is linked to the main data table on the field Assessement_MonthStart.

The data provided is based on a client ID, the date they were assessed (Date_Assessed) and the date they were discharged (DISCHARGE). A flag, Client_Effective_Treatment, has a 1 if treatment considered successful and a 2 if not successful.

When running the expression =count(distinct If(Client_Effective_Treatment=1,Client_ID)) for any given month it (naturally!) counts only those records where the field Assessement_MonthStart = that month e.g. Apr 10 = count of 3.

What I really want is to count all those in successful treatment (Client_Effective_Treatment=1) in that month, not just those assessed in that month. A client could have been assessed the months before (e.g. Feb 10) and is still actively a client in effective treatment in April. Only when a client has been discharged then in the month after discharge they should not be counted. If there is no Discharge date and Client_Effective_Treatment=1 then they should be counted each month.

So in essence if I want to fix the x-axis with set months, how do you count valid records that are active in that month but is only evidenced by a Date_Assessed prior to that mont and a Discharge Date equal to or later than that month?

The tables below show the records that should be counted in each month - April 5, May=5, June=7.

Any help/suggestions will be greatly appreciated.

Many thanks Neil.

Data that should be counted in April
Client_AttribClient_Effective_TreatmentDate_AssessedDISCHARGE
M-C-5/1/1970-M112/06/2009
M-D-19/6/1971-M115/01/2010
A-S-23/3/1972-M112/02/2010
M-K-12/3/1956_M112/03/201030/03/2010
J-Y-12/4/1974-M101/04/201030/04/2010
A-N-1/7/1971-M110/04/201030/05/2010
M-C-10/1/1975-M118/04/2010
L-C-1/4/1972-M203/05/201004/06/2010
K-H-8/12/1980-F204/05/201005/06/2010
D-S-26/3/1988-M115/05/201016/06/2010
D-M-8/12/1984-M104/06/201005/07/2010
N-H-9/11/63-M122/06/201030/07/2010
Data that should be counted in May
Client_AttribClient_Effective_TreatmentDate_AssessedDISCHARGE
M-C-5/1/1970-M112/06/2009
M-D-19/6/1971-M115/01/2010
A-S-23/3/1972-M112/02/2010
M-K-12/3/1956_M112/03/201030/03/2010
J-Y-12/4/1974-M101/04/201030/04/2010
A-N-1/7/1971-M110/04/201030/05/2010
M-C-10/1/1975-M118/04/2010
L-C-1/4/1972-M203/05/201004/06/2010
K-H-8/12/1980-F204/05/201005/06/2010
D-S-26/3/1988-M115/05/201016/06/2010
D-M-8/12/1984-M104/06/201005/07/2010
N-H-9/11/63-M122/06/201030/07/2010
Data that should be counted in June
Client_AttribClient_Effective_TreatmentDate_AssessedDISCHARGE
M-C-5/1/1970-M112/06/2009
M-D-19/6/1971-M115/01/2010
A-S-23/3/1972-M112/02/2010
M-K-12/3/1956_M112/03/201030/03/2010
J-Y-12/4/1974-M101/04/201030/04/2010
A-N-1/7/1971-M110/04/201030/05/2010
M-C-10/1/1975-M118/04/2010
L-C-1/4/1972-M203/05/201004/06/2010
K-H-8/12/1980-F204/05/201005/06/2010
D-S-26/3/1988-M115/05/201016/06/2010
D-M-8/12/1984-M104/06/201005/07/2010
N-H-9/11/63-M122/06/201030/07/2010


1 Solution

Accepted Solutions
johnw
Champion III
Champion III

For April and May 2010, why aren't you counting the first line? There is no discharge date, and they were assessed before April 2010. Did you mean to put in a 2010 date instead of a 2009 date? That's my guess. Given that...

Add a unique ID to the Main_PDU table:

LOAD recno() as ID, * INLINE ...

Then intervalmatch the treatment months between the assessment and discharge with that table linked to the main one by the unique ID:

AllTreatmentMonths:
LOAD date(TreatmentMonth,'MMM YY') as TreatmentMonth
INLINE [
TreatmentMonth
01/04/2010
01/05/2010
01/06/2010
01/07/2010
01/08/2010
01/09/2010
01/10/2010
01/11/2010
01/12/2010
01/01/2011
01/02/2011
01/03/2011];

TreatmentMonths:
LOAD ID, Assessement_MonthStart as Start, if(DISCHARGE,monthend(DISCHARGE),date#(99990101,'YYYYMMDD')) as End
RESIDENT Main_PDU
;
LEFT JOIN (TreatmentMonths)
INTERVALMATCH (TreatmentMonth)
LOAD Start, End
RESIDENT TreatmentMonths
;
DROP TABLE AllTreatmentMonths;
DROP FIELDS Start, End;

See attached.

View solution in original post

2 Replies
johnw
Champion III
Champion III

For April and May 2010, why aren't you counting the first line? There is no discharge date, and they were assessed before April 2010. Did you mean to put in a 2010 date instead of a 2009 date? That's my guess. Given that...

Add a unique ID to the Main_PDU table:

LOAD recno() as ID, * INLINE ...

Then intervalmatch the treatment months between the assessment and discharge with that table linked to the main one by the unique ID:

AllTreatmentMonths:
LOAD date(TreatmentMonth,'MMM YY') as TreatmentMonth
INLINE [
TreatmentMonth
01/04/2010
01/05/2010
01/06/2010
01/07/2010
01/08/2010
01/09/2010
01/10/2010
01/11/2010
01/12/2010
01/01/2011
01/02/2011
01/03/2011];

TreatmentMonths:
LOAD ID, Assessement_MonthStart as Start, if(DISCHARGE,monthend(DISCHARGE),date#(99990101,'YYYYMMDD')) as End
RESIDENT Main_PDU
;
LEFT JOIN (TreatmentMonths)
INTERVALMATCH (TreatmentMonth)
LOAD Start, End
RESIDENT TreatmentMonths
;
DROP TABLE AllTreatmentMonths;
DROP FIELDS Start, End;

See attached.

Not applicable
Author

Good Morning John.

Thank you very much for taking the time and effort to respond to my request for help. Will have a look and see how I get on. If you have a spare copy of your Qlikview Brain that you could send to me then my life would be sorted.

Once again thank you.

Best regards Neil