Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
jerryr125
Creator III
Creator III

Firstsortedvalue - calculation

Hi -

I am trying to calculate the total number of quantity by the last date by state.

1. I created the following variable:

 

vquantitylocation

=IF(LEN(Category)>0,location)

** This is created so that it removes any values from my data in which the Category is Null.

 

2. I create the following master measure:

 

firstsortedvalue(Aggr(sum(quantity),$(vquantitylocation) ,-date)

 

Does not work - any thoughts ?? Thanks - Jerry

1 Solution

Accepted Solutions
tresesco
MVP
MVP

That is because, you are making the same mistake, using if(sum( .... structure instead of sum(if(... (I suggested above). 

Expression to be tried:

SUM({<POPESTIMATE2020={">0"},[date.autoCalendar.Date]={'$(=Max([date.autoCalendar.Date]))'}>}people_fully_vaccinated)

 

Please close the thread by liking and/or marking correct answer. That would help others as well. 

View solution in original post

14 Replies
jerryr125
Creator III
Creator III
Author

Hi -  also tried :

firstsortedvalue(Aggr(sum(quantity), date ,-date)

 

No luck - an assistance would be appreciated - Jerry

jerryr125
Creator III
Creator III
Author

Hi - I also tried the following :

firststortedvalue(quantity,-date)

Only works when you filter out on a specific location.

How can I get the function to work regardless of filtering on location or not ?

I also need to remove the locations which invalid :

vquantitylocation

IF(LEN(Category)>0,location)

 

Any thoughts would be appreciated - stuck on this one - Jerry

 

 

tresesco
MVP
MVP

What is your dimension in chart?

jerryr125
Creator III
Creator III
Author

Hi tresesco -

I created a master measure to display in my tables, kpis, etc...

Master measure :

mmQuantityYTD

Expression :

firstsortedvalue(quantity,-date)

 

Need to remove the invalid locations thus I tried to create a variable to do so and then add it to the firstsortedvalue function:

vquantitylocation

IF(LEN(Category)>0,location)

 

I tried this and no luck:

firstsortedvalue(Aggr(sum(quantity),$(vquantitylocation) ,-date)

tresesco
MVP
MVP

Where are you trying this? In KPI , or chart?

Also, in aggr(,<dimensions>), the second parameter is expected to be field name(s) and not an expression. If you can share an app with sample data and explain the expected output w.r.t that data,  it could be easier for us to help.  

jerryr125
Creator III
Creator III
Author

Hi again Tresesco - 

Although I cannot share the application, here is what I can trying to achieve :

 

jerryr125_0-1619610333294.png

 

It seems as if the FirstSortedValue needs to remove the Locations with the Categories that are null.

 

Thoughts  ? Thanks - Jerry

tresesco
MVP
MVP

Try like:

FirstSortedValue( {<Category={"=Len(Category)>0"}>}Aggr(Sum(quantitysold), Date, Location,Category), -Date)

tresesco_0-1619611782375.png

 

jerryr125
Creator III
Creator III
Author

Hi - thank you again for your help.

Getting very close.

This formula works if you select ONLY one location. When you select more than one location - no luck

 

FirstSortedValue( Aggr(Sum(quantity),[date.autoCalendar.Date], location,[Category]), -[date.autoCalendar.Date])

 

If I can take this formula and filter on the Categories were the LEN is >0 then we should be good...

 

 

This did not work (seems to not recognize the Category field with this syntax:

"=Len(Category)>0"

 

FirstSortedValue( {<Category={"=Len(Category)>0"}>}Aggr(Sum(quantitysold), Date, Location,Category), -Date)

 

Thoughts ? Jerry

 

 

jerryr125
Creator III
Creator III
Author

Hi Tresesco - I sent you a private message with further information.

Thanks - Jerry