Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
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

1 Solution

Accepted Solutions
sunny_talwar

May be this:

=FirstSortedValue({<MonthNum = {"$(=Max(MonthNum))"}>}Aggr(Sum(Stoc), Date, Company), -Aggr(Date, Date, Company))

Script:

Table:

LOAD *,

  Month(Date) as Month,

  Num(Month(Date)) as MonthNum;

LOAD * INLINE [

    Company, Date, Stoc

    X, 30/05/2016, 10

    Y, 31/05/2016, 20

    Z, 31/05/2016, 30

    X, 30/04/2016, 40

    Y, 01/05/2016, 10

    Z, 02/05/2016, 30

    X, 28/03/2016, 40

    Y, 31/03/2016, 50

    Z, 31/03/2016, 10

    X, 27/03/2016, 20

    Y, 31/03/2016, 30

    Z, 01/04/2016, 40

];

Without Selection

Capture.PNG

With Selection

Capture.PNG

View solution in original post

20 Replies
swuehl
MVP
MVP

Try Company as dimension in your chart and

=FirstSortedValue(Stoc, -Date)

as expression. Take care that your Date field values need to show a numeric representation.

lavielme
Creator
Creator
Author

Can I Do  FirstSortedValue(Stoc, -Date(Date,'DD/MM/YYYY'))

sunny_talwar

May be this:

=FirstSortedValue({<MonthNum = {"$(=Max(MonthNum))"}>}Aggr(Sum(Stoc), Date, Company), -Aggr(Date, Date, Company))

Script:

Table:

LOAD *,

  Month(Date) as Month,

  Num(Month(Date)) as MonthNum;

LOAD * INLINE [

    Company, Date, Stoc

    X, 30/05/2016, 10

    Y, 31/05/2016, 20

    Z, 31/05/2016, 30

    X, 30/04/2016, 40

    Y, 01/05/2016, 10

    Z, 02/05/2016, 30

    X, 28/03/2016, 40

    Y, 31/03/2016, 50

    Z, 31/03/2016, 10

    X, 27/03/2016, 20

    Y, 31/03/2016, 30

    Z, 01/04/2016, 40

];

Without Selection

Capture.PNG

With Selection

Capture.PNG

swuehl
MVP
MVP

If you need to interpete your date values, this should work

FirstSortedValue(Stoc, -Date#(Date,'DD/MM/YYYY'))

But it would be better to do in the script.

SET DateFormat = 'DD/MM/YYYY';

sunny_talwar

More like this:

FirstSortedValue(Stoc, -Date#(Date,'DD/MM/YYYY'))

lavielme
Creator
Creator
Author

why the total line is null()???

swuehl
MVP
MVP

You can also try something like

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

Again, take care that Date shows a numeric representation.

lavielme
Creator
Creator
Author

Thank you very much, Sunny. That was the exactly thing that I searched.

Note: Edited by Community Moderator. Please do not post in all capital letters.

Not applicable

Hi,

Total null can be set by changing total mode in expression tab from. select "sum of rows".

Thanks