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: 
mansi_dv
Contributor
Contributor

Use of maxstring() function

I want an expression like this.

=sum({<[Month] = {"April"}, Year = {"2012-13"}>}Data)

This works correctly but now I want month and year selected by the user from a list. I could have done it with GetFeildSelections() but I am using alternate States and GetFeildSelections() does not work with alternate states. So I used maxstring() function.

Having my state name as 'new', I did it as follows:

=sum({<[Month] = maxstring({[new]} [Month]),[Year] = maxstring({[new] [Year]})>}Data)

=sum({<[Month] = maxstring({[new]} [Month])>*<[Year] = maxstring({[new] [Year]})>}Data)

But its showing "error in set modifier element function name".

Then I tried creating variables for Month and Year as:

vMonth = maxstring({[new]} [Month])  and

vYear = maxstring({[new]} [Year])

still no correct output.

Anybody has a solution for this?

1 Solution

Accepted Solutions
perumal_41
Partner - Specialist II
Partner - Specialist II

Hi ,

Try below expression

=sum({<[Month] = {'$(=maxstring({[new]} [Month]))'},[Year] = {'$(=maxstring({[new]}[Year]))'}>}Data)

=sum({<[Month] = {'$(=maxstring({[new]} [Month]))'}>*<{'$(=maxstring({[new]}[Year]))'}>}Data)

View solution in original post

10 Replies
Anonymous
Not applicable

Please post a sample app so that we can have a look to help you in a better way

PrashantSangle

Hi,

Instead of using MaxString() You can use Only Max function

Like this,

=sum({<[Month] ={"=max([Month]"},[Year] ={"=max([Year])"}>}Data)


Regards,

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
Not applicable

Hi Mansi,

Try this approach. Declare variables for your month and year.

e.g. vMonthnew =concat({new}Month)

      vYearnew =concat({new} Year)

Now use the variable directly in the set analysis. That is more readable as well. You don't need maxstring.


sushil353
Master II
Master II

Hi,

First of all check your variable values using a text box.. see if the values are desired or not.

if all is well then you can try below expression:

=sum({<[Month] = $(vMonth ),[Year] = $(vYear )>}Data)


HTH

Sushil

perumal_41
Partner - Specialist II
Partner - Specialist II

Hi ,

Try below expression

=sum({<[Month] = {'$(=maxstring({[new]} [Month]))'},[Year] = {'$(=maxstring({[new]}[Year]))'}>}Data)

=sum({<[Month] = {'$(=maxstring({[new]} [Month]))'}>*<{'$(=maxstring({[new]}[Year]))'}>}Data)

VishalWaghole
Specialist II
Specialist II

Hello Mansi,

No need to use maxstring here, You can just try with this

=Sum({<Month ={"$(MaxMonth)"},Year ={"$(MaxYear)"}>} Data)

Hope it will help you

- Regards,

Vishal Waghole

VishalWaghole
Specialist II
Specialist II

Hello Mansi,

I forgate to tell you that, you have to declared two variable.

MaxMonth = Date(Max(Month(DateField)),'MMM')

MaxYear = Date(Max(Year(DateField)),'YYYY')

then use above expression.

mansi_dv
Contributor
Contributor
Author

I checked for my variables, they are working fine except that when nothing is selected - I get output as the last value in my listbox. What can be done to correct this?

And for the expression you gave, I am getting some output instead of the earlier one where i used to get zero but it is  not the desired result.

sushil353
Master II
Master II

Hi Mansi,

Post your sample application for better resolution.

~Sushil