Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Help required for calculation in chart for date difference

Dear Expert,

Need help for EQUNR_S to get Act_Typ difference for same field Doc-Date.

How to calculate the same in chart or while loading.

IDShip_KeyDoc_DateEQUNR_SAct_Typget date difference
10000000001000101397Z2001.02.20111397ER0
130000000002000101397Z3001.02.20111397E0.00
100760000001797000201397Z3010.06.20111397F129.00
100780000001798000201397Z3013.06.20111397D3.00
100800000001799000201397Z2013.06.20111397T0.00
112560000002262000101397Z2016.07.20111397ER33.00
131890000003284000101397Z3029.10.20111397I105.00

Thanks

Ashif

1 Solution

Accepted Solutions
jagan
Luminary Alumni
Luminary Alumni

HI,

Try like this

Temp:

LOAD *, if(previous(EQUNR_S=EQUNR_S, Doc_Date - previous(Doc_Date),0) as TT,

if(previous(EQUNR_S<>EQUNR_S, 1, 0) AS Flag,

if(previous(EQUNR_S=EQUNR_S, RangeSum(Peek([TT]), Doc_Date - previous(Doc_Date)), (Doc_Date - previous(Doc_Date)) AS AccumSum

Resident Temp

Order By EQUNR_S, Doc_Date; 

Result:

NoConcatenate

LOAD *,

if(previous(EQUNR_S<>EQUNR_S, 1, 0) AS Flag

Resident Temp

Order By EQUNR_S, Doc_Date DESC; 

Now in front end

Chart : Straight Table

Dimension: EQUNR, Act_Typ

Expression: Sum({<Flag ={1}>}AccumSum)


REgards,

Jagan.

View solution in original post

10 Replies
Gysbert_Wassenaar

Maybe like this:

LOAD

     ID,

     Ship_Key,

     Doc_Date,

     EQUNR_S,

     Act_Typ,

     If(EQUNR_S=previous(EQUNR_S),Doc_Date - previous(Doc_Date),0) as [get date difference]

FROM

     ...somewhere...

;


talk is cheap, supply exceeds demand
Not applicable
Author

Dear Gysbert,

Above data is sor

Its giving 0 value in load statement as mentioned by you.

Thanks

Ashif

Gysbert_Wassenaar

Your Doc_Date field contains only one value. Every record has the same Doc_Date value, so there's never a difference between the Doc_Date value of one record and the Doc_Date value of another record.


talk is cheap, supply exceeds demand
Not applicable
Author

I've loaded all the records with example. Check the same. There is difference in date.

Gysbert_Wassenaar

I think the problem is that your data is not sorted by EQUNR_S first. You can resolve that using a resident load with an order by clause.

Temp:

LOAD * FROM YourQVD (qvd);

Result:

LOAD *, if(previous(EQUNR_S=EQUNR_S, Doc_Date - previous(Doc_Date),0) as TT;

Resident Temp

Order By EQUNR_S, Doc_Date;    


talk is cheap, supply exceeds demand
jagan
Luminary Alumni
Luminary Alumni

Hi,

Can you post the entire script, are you using any aggregate functions like Sum(), Count(), Max(), Min() etc.  If you are using then use Group by in script like below

Load EQUNR_S,

     Doc_Date,

Sum(SomeField) AS Total

FROM DataSource

Group by EQUNR_S, Doc_Date; -- You have to specify all the fields here given in the Load.

Hope this helps you.

Regards,

Jagan.

Not applicable
Author

Now i want the chart to appear like this

IDEQUNRAct_TypSenderReceiverDoc_TypeDoc_DateOperation time
20153ER000000294801/02/2011
21693E0000002948000000294801/02/2011282
145113F0000002948000000294810/11/2011296
251603D0000002948000000294801/09/201230
256673ER0000003398000000339801/10/20120
256683C0000003398000000339801/10/20120
256683C0000003398000000339801/10/20120
256663T0000002948000000339801/10/2012

Help me with chart expression to get the result as current result is getting like this.

EQUNRAct_TypOperation time
3D-578
3F326
jagan
Luminary Alumni
Luminary Alumni

Hi,

Add one more column in script like below

Result:

LOAD *, if(previous(EQUNR_S=EQUNR_S, Doc_Date - previous(Doc_Date),0) as TT,

if(previous(EQUNR_S<>EQUNR_S, 1, 0) AS Flag,

if(previous(EQUNR_S=EQUNR_S, RangeSum(Peek([TT]), Doc_Date - previous(Doc_Date)), (Doc_Date - previous(Doc_Date)) AS AccumSum

Resident Temp

Order By EQUNR_S, Doc_Date;  

Now in front end

Chart : Straight Table

Dimension: EQUNR, Act_Typ

Expression: Sum({<Flag ={1}>}AccumSum)

Hope this helps you.

Regards,

Jagan.

Not applicable
Author

Still not gettong the desired result.

IDEQUNR_SAct_TypDoc_Date
20153ER01/02/20110
21693E01/02/2011282
145113F10/11/2011296
251603D01/09/201230
256663T01/10/20120
256673ER01/10/20120
256683C01/10/20120