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

Announcements
Discover the Trends Shaping AI in 2026: Register Here!
cancel
Showing results for 
Search instead for 
Did you mean: 
lavielme
Creator
Creator

SET EXP

Hey everyone

Lats say i have this data:

   

CompanyDateStoc
X30/05/201610
Y31/05/201620
Z31/05/201630
X30/04/201640
Y01/05/201610
Z02/05/201630
X28/03/201640
Y31/03/201650
Z31/03/201610
X27/03/201620
Y31/03/201630
Z01/04/201640

and i need an expression who can Calculate For each Company the last stock in a table for example if i don't choose anything

the table will be like that:

Company     Stoc

X                    10

Y                   20

Z                    30

If i choos march and aprill

Company     Stoc

X                     40

Z                    40

Y                    0

Best Regards

Lavi

20 Replies
sunny_talwar

What would you like to see for the total line?

lavielme
Creator
Creator
Author

‌i solved that with aggr thank's

swuehl
MVP
MVP

If you want to filter the month, you can also add the set expression to my last expression:

Sum(

     {<MonthNum = {"$(=Max(MonthNum))"}>}

Aggr( If( Date = Max(Total<Company> Date), Sum(Stoc)), Company, Date))

This should return the correct total, too. And saves you one advanced aggregation

Company =FirstSortedValue({<MonthNum = {"4"}>}Aggr(Sum(Stoc), Date, Company), -Aggr(Date, Date, Company)) Sum({<MonthNum = {"4"}>} Aggr( If( Date = Max(Total<Company> Date), Sum(Stoc)), Company, Date))
40 80
X4040
Z4040
sunny_talwar

But Stefan we are already in the straight table, why even need to use Aggr() for that. Why not use the total mode as pointed by Amit‌?

Capture.PNG

swuehl
MVP
MVP

Which of your aggr() function would you drop then?

sunny_talwar

I did not mention dropping any aggr . My comment was related to getting the total right

swuehl
MVP
MVP

Sure, you can change the total mode.

I personally prefer a solution that will also work in a text box or when changing the chart to a pivot table, and if this solution comes with no additional cost, fine.

sunny_talwar

I always thought that Aggr() function should be avoided as it can be resource extensive. Although I am using two in my expression, but in general it seems that you are saying that

Avg(Aggr(Sum(Sales), Product)) is better than using Sum(Sales) and using Avg as total mode (in straight table)?

swuehl
MVP
MVP

Hi Sunny,

sorry, it's getting late in here.

Not sure if I understand what you are trying to tell me.

I would agree that in general, I try to avoid the aggr() function since it's creating some overhead and may also show issues w.r.t the (chart) dimensions it's getting projected on.

It all depends on the requirements and context, but if I can chose between two expressions that return the same on the details lines with a similar complexity, but one delivers the correct totals (correct w.r.t to my requirements) and can also be kept when changing e.g. the chart style, I would prefer this over the other.

This does not mean that the other expression is wrong.

sunny_talwar

Got it. Thanks for taking out time to go over this in detail for us