Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Hakim-A
Creator
Creator

Sum each last value by field

Hello,

I am facing a problem I can't solve.

I have data like this :

tab1.PNG

And I'd like to display for each chassis 1, 2 & 3 the sum of each last value of counter (by last value, it is the value of counter where day=max(day)) for all variants, so this result:

result.PNG

I could then filter on a certain variant and see the value for this specific variant

For example if I select A & C I'd have :

a&c.PNG

Thanks for your contribution, it really drives me crazy not to find a way to solve this.

1 Solution

Accepted Solutions
Anonymous
Not applicable

Hi hakim,

You can flag your data on script:

LEFT JOIN

LOAD

    Max(day) as day,

    chassis,

    variant,

    1 as LastDayFlag

RESIDENT Sheet3

GROUP BY chassis, variant;

Then, on your expression:

=Sum({<LastDayFlag={1}>}counter)

Regards!!

View solution in original post

8 Replies
Anil_Babu_Samineni

How you are calculating Sum Latest Counter

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
sunny_talwar

Try this expression:

=Sum(Aggr(FirstSortedValue(Counter, -Day), Chassis, Variant))


Capture.PNG

Hakim-A
Creator
Creator
Author

Hi,

Thanks for the quick replies.

Sum latest counter is calculated as so = For each chassis we sum the values of counter of all distinct Variant where day=max(day)

Sunny, your solution is not working I tried it with my data and I've errors.

See enclosed if you select chassis b-749444 and variant u3000 then the result is 20 and it should be 39 787

In fact there are double values for this chassis and variant so I think QV is confused

See in the excel file you'll understand immediately

sunny_talwar

Do you mean 39867?

Capture.PNG

May be try this:

=Sum(Aggr(FirstSortedValue(Aggr(Sum(counter), chassis, variant), -Aggr(day, chassis, variant)), chassis, variant))

Hakim-A
Creator
Creator
Author

Actually the result should be 39 792 : 1+13+1+5+6+39766

For each chassis having the same variant and same day we should take the maximum of counter

The formula is yet not valid really strange

Thank you for contribution

Anonymous
Not applicable

Hi hakim,

You can flag your data on script:

LEFT JOIN

LOAD

    Max(day) as day,

    chassis,

    variant,

    1 as LastDayFlag

RESIDENT Sheet3

GROUP BY chassis, variant;

Then, on your expression:

=Sum({<LastDayFlag={1}>}counter)

Regards!!

sunny_talwar

This is a new information which you did not tell before. Try this

=Sum(Aggr(FirstSortedValue(Aggr(Max(counter), chassis, variant), -Aggr(day, chassis, variant)), chassis, variant))

Capture.PNG

Hakim-A
Creator
Creator
Author

Sorry for late reply

I managed to build a solution thanks to your contributions.

Many thanks