Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
Sara_3
Creator
Creator

Calculated Field with Auto Generated Date Field.

Hello ,

My requirement is to get Calculated field "Days Aged within PO DOC and PO ITEM , but getting this field I have to do some steps. I am able to do in excel but not able to do in qlik. 

My data is :

Table A:

LOad *,

PO DOC,

PO ITem,

As of Date

From QVD;

I have PO DOCs and its multiple PO Items with As of Dates.  I selected the PO DOC with PO ITEM = 10 .

Data:

Sara_3_1-1696816744108.png

Expected Field "Days Aged" :

Sara_3_0-1696825182634.png

Steps to get the Expected Field "Days Aged":

Step 1 : Create Min and Max (As of Days) field within / group by PO DOC and POITem. 

Min (As of Date ) = 09/21/2020   and Min ( As of Date) = 09/25/2023

Step 2: create a auto generated Date field between Min and Max Dates (like auto generated field for the above data between 09/21/2020 - 09/25/2023)

Step 3 : Create Flag 1, Check (if [As of Date] matched/ exists in Auto generated Date field , 'YES', 'NO')

 Flag 1 (column 4)

Sara_3_1-1696825433903.png

Step 4: Create Flag 2 - if (As of Date has previous data (As of Date), 'YES','NO') as Flag 2 (Column 5)

Sara_3_2-1696825509427.png

Step 5 : Field "Days Aged" (if (both Flags = 'YES' start with '0' and Range SUM (Current (As of Date ) - Previous (As of Date) . (Column 6) 

Sara_3_3-1696825577039.png

Step 6 : Expected Field:

Days Aged = 85 with MAX (as of Date)

Sara_3_4-1696825860433.png

Thanks in advance .

 

 

 

 

 

 

1 Reply
Qlik_BA
Contributor
Contributor

Hi Sara,

 Try this. I hope it works for you,

Use DateDiff() to calculate the days elapsed between "Starting from Date" and "As of Date."

  • Create a calculated field with these elapsed days.
  • Filter the data for PO DOC with PO ITEM = 10 using WHERE.
  • Script :

Table:

LOAD *,

DateDiff('days', [Starting from Date], [As of Date]) AS [Days Elapsed]

FROM [your QVD file.qvd]

WHERE [PO ITEM] = 10;