Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
rathorep
Contributor III
Contributor III

sum for if expression

I have below expression:

//sum(Aggr(

if( if( if (NetWorkDays(date(Above(TOTAL [Field Modified Date],1),'DD/MM/YYYY'),Date([Field Modified Date],'DD/MM/YYYY')-1) < (floor(sum(Aggr( if ("Field Modified Group Code"=$(vFieldModifiedGroupCode), Interval(sum(Aggr(Interval(Rangemax(Interval((Above(TOTAL [Field Modified Date],1) - [Field Modified Date])*(-1), 'd.hh.mm'),0),'d.hh.mm'), [Win@proach Ticket Number],([Field Modified Date], (NUMERIC)))),'d.hh:mm'),0 ),[Win@proach Ticket Number],([Field Modified Date],(NUMERIC)))))) , ((( (interval(sum(Aggr( if ("Field Modified Group Code"=$(vFieldModifiedGroupCode), Interval(sum(Aggr(Interval(Rangemax(Interval((Above(TOTAL [Field Modified Date],1) - [Field Modified Date])*(-1), 'd.hh.mm'),0),'d.hh.mm'), [Win@proach Ticket Number],([Field Modified Date], (NUMERIC)))),'d.hh:mm'),0 ),[Win@proach Ticket Number],([Field Modified Date],(NUMERIC)))),'d.hh:mm'))) - interval( (round(sum(Aggr( if ("Field Modified Group Code"=$(vFieldModifiedGroupCode), Interval(sum(Aggr(Interval(Rangemax(Interval((Above(TOTAL [Field Modified Date],1) - [Field Modified Date])*(-1), 'd.hh.mm'),0),'d.hh.mm'), [Win@proach Ticket Number],([Field Modified Date], (NUMERIC)))),'d.hh:mm'),0 ),[Win@proach Ticket Number],([Field Modified Date],(NUMERIC)))))) - (NetWorkDays(date(Above(TOTAL [Field Modified Date],1),'DD/MM/YYYY'),Date([Field Modified Date],'DD/MM/YYYY')-1)),'d.hh.mm') )) , (if ("Field Modified Group Code"=$(vFieldModifiedGroupCode), (sum(Aggr(Interval(Rangemax(Interval((Above(TOTAL [Field Modified Date],1) - [Field Modified Date])*(-1), 'd.hh.mm'),0),'d.hh.mm'), [Win@proach Ticket Number],([Field Modified Date], (NUMERIC))))),0 )))>'2.75' and Remarks <>'Exception','Exceeded Target',if((([Field Modified Group Code]<>$(vFieldModifiedGroupCode)) and Remarks='Exception'),'NA','Meet Target')) ='Exceeded Target', count( {<[Field Modified Group Code]={$(vFieldModifiedGroupCode)} , [Record Type] = {'IR'}, Severity={'Medium'}>}distinct [Win@proach Ticket Number]) ,0)

//,[Win@proach Ticket Number]))

Result I am getting is:

Win@proach Ticket NumberField Modified DateWith the Expression shared
1972647/24/2020 14:380
1972647/27/2020 7:070
1972647/30/2020 13:211
1972647/30/2020 14:270
1972648/18/2020 23:120
20325711/10/2020 9:180
20325711/10/2020 9:220
20325711/25/2020 13:071
20325711/26/2020 12:390
20325711/26/2020 13:170
20325712/2/2020 0:110

Now i need to calculate sum on top of this, so when i am un commenting first and last bold lines, Its giving 0 in full column and total also is coming 0. Sum should be 2 Could any one help me urgently please.

2 Solutions

Accepted Solutions
tresesco
MVP
MVP

Well, one more check; are you using [Field Modified Date] as a dimension/field in the above table? If so, you might need to include the same field in aggr() as well, like:

Sum(Aggr(.... ) ,[Win@proach Ticket Number], [Field Modified Date]))

 

View solution in original post

ArnadoSandoval
Specialist II
Specialist II

Hi @rathorep 

Perhaps there is a better way to do it, but you should share with us more about your data model and the rules to count the weekends between two dates, I found this topic ¿How to count Saturdays in date range?  I even wrote a simple QVF application exploring the WeekDay function potential,  the expression you posted does not implement the WeekDay function.

Please take a look at the attached QVF file.

Arnaldo Sandoval
A journey of a thousand miles begins with a single step.

View solution in original post

8 Replies
tresesco
MVP
MVP

I would not go much into the expression (such a huge one !). Try a quick possible fix. Include NoDistinct in aggr() like:

Sum(Aggr( NoDistinct (...

rathorep
Contributor III
Contributor III
Author

Hello, Thanks for quick reply, But I did not get correct sum with nodistinct.

tresesco
MVP
MVP

Well, one more check; are you using [Field Modified Date] as a dimension/field in the above table? If so, you might need to include the same field in aggr() as well, like:

Sum(Aggr(.... ) ,[Win@proach Ticket Number], [Field Modified Date]))

 

ArnadoSandoval
Specialist II
Specialist II

Hi @rathorep 

Who will support that huge expression in your code? next week or next month, it looks like a dish of spaghettis; Would you help us and yourself by formatting that expression? I tried, even with 2 meters of video it is a daunting task! It will take me about 3 days to simplify your code.

hth 

Arnaldo Sandoval
A journey of a thousand miles begins with a single step.
rathorep
Contributor III
Contributor III
Author

Hi @ArnadoSandoval 

I completely agree that the code is very huge and it should be a simplified one and formatted one. but the reason of it is we can not substract weekends between 2 dates(please let me know if we have direct function to the number of weekends). I am sorry to put this much huge code. I understand its very messy 😞

rathorep
Contributor III
Contributor III
Author

Hi @tresesco 

I had tried this one before but not sure what i was doing wrong but you are amazing , it gave me the correct sum now ..Thanks a ton !!!! once again sorry to share this much long code...

If we can directly have the number of weekends between 2 dates please let me know. it will help me to shortened my code ...

 

ArnadoSandoval
Specialist II
Specialist II

Hi @rathorep 

Perhaps there is a better way to do it, but you should share with us more about your data model and the rules to count the weekends between two dates, I found this topic ¿How to count Saturdays in date range?  I even wrote a simple QVF application exploring the WeekDay function potential,  the expression you posted does not implement the WeekDay function.

Please take a look at the attached QVF file.

Arnaldo Sandoval
A journey of a thousand miles begins with a single step.
Ksrinivasan
Specialist
Specialist

hi,

in load script, you can add this if function

(If(WeekDay("YourDatefield") = 'Sat','SATUREDAY',If(WeekDay("YourDatefield") = 'Sun','SUNDAY','')) as WEEKENDDAYS,)

and get sat and Sun day in new field,

you can use this  values in Chart or table expression without that huge script,

qlik performance would be slow by your script.

Regards,

K. Srinivasan.