Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
apoorvasd
Creator II
Creator II

Firstsortedvalue function with sum in QlikView

Hello Everyone,

I am using firstsortedvalue function to pick up last value in date field for a particular month. But I would like to combine this with sum function. What I want is, in the attached example, when more than two plants are selected, my graph should display value which is the sum of last value of date field of that particular month combining both plants (sum). How can I achieve this?

Any suggestion?

Thank you.

1 Solution

Accepted Solutions
rubenmarin

Another approach to check first date of the month:

If(Month(Date#(POPER_NEW, 'MMM'))>=month(today()) or WeekShort>=Today()

,Sum(Aggr(If(WeekShort=Min(TOTAL <Plant> WeekShort), Sum({<KPI={"Inventory_New"}>}[w/o BB]))

, Plant, WeekShort))

,Sum(Aggr(

If(WeekShort=Min(TOTAL <Plant> WeekShort),

  Sum({<KPI={"Inventory_New"}>}[ACT Inventory weekly LC])-Sum({<KPI={"Inventory_New"}>}[AOP Inventory monthly LC]))

, Plant, WeekShort))

)

View solution in original post

13 Replies
rubenmarin

Hi, you can try with:

Sum(Aggr(FirstSortedValue(DISTINCT{<[ACT vs AOP]={'>0'}, Date={'<=$(=Today())'}>}[ACT vs AOP],-Date), [$(=GetCurrentField(@Time))], Plant))

sunny_talwar

Just suggest to add the set analysis from the inner aggregation to the outer one

Sum({<Date={'<=$(=Today())'}>} Aggr(FirstSortedValue(DISTINCT{<[ACT vs AOP]={'>0'}, Date={'<=$(=Today())'}>}[ACT vs AOP],-Date), [$(=GetCurrentField(@Time))], Plant))

rubenmarin

Right, things of quick-answering

I didn't checked but, shouldn't be all set analysis?

Sum({<[ACT vs AOP]={'>0'}, Date={'<=$(=Today())'}>} Aggr(FirstSortedValue(DISTINCT{<[ACT vs AOP]={'>0'}, Date={'<=$(=Today())'}>}[ACT vs AOP],-Date), [$(=GetCurrentField(@Time))], Plant))

sunny_talwar

Ya that's true

apoorvasd
Creator II
Creator II
Author

It's working! Thank you very much Ruben

apoorvasd
Creator II
Creator II
Author

Whose answer should I mark as right one now?

apoorvasd
Creator II
Creator II
Author

Quick question on this again. How will I get this to work in an "if" "else" statement written below?

if(GetFieldSelections(WeekShort)>=month(Date#(WeekShort,'MMM')) or  Month(Date#(POPER_NEW, 'MMM'))>=month(today())

,FirstSortedValue(DISTINCT {<KPI={"Inventory_New"}>}[Risk/ Challenge - Bank Builds],-Date)

,if(GetFieldSelections(WeekShort)<month(Date#(WeekShort,'MMM')) or Month(Date#(POPER_NEW, 'MMM'))<month(today())

,FirstSortedValue(DISTINCT {<KPI={"Inventory_New"}>}[BB ACT monthly LC]-[BB FC monthly LC],-Date)))

Thank you.

rubenmarin

Hi Apoorva, I'm not sure if taking the aggr outside the expression can work, and what dimensions should be used as parameters in that case. Can you upload a sample to test?

Btw, I don't think "GetFieldSelections(WeekShort)>=month(Date#(WeekShort,'MMM'))" is working, what has to do this filter?

apoorvasd
Creator II
Creator II
Author

Hi Ruben,

I have uploaded the sample.

WeekShort field has dates as its values. What that condition does is, when a value selected in WeekShort is greater than or equal to current month then do so and so...Complete expression is available in the attached sample.

Thank you.