# New to Qlik Sense

If you’re new to Qlik Sense, start with this Discussion Board and get up-to-speed quickly.

Announcements
QlikWorld Online 2021, May 10-12: Our Free, Virtual, Global Event REGISTER TODAY
cancel
Showing results for
Did you mean:
Contributor

## Formula within set analysis not working

Hi all

The following expression works:

=Count( {<Brand= {CD}>} Aggr( Count(Distinct Code),Shop,Code))  // Result=899

=Firstsortedvalue (Brand, -Aggr(Count({<Brand=>} Code), Brand), 1) //  Result = CD

This one is not working. I just replaced the brand CD on the first expression for the second expression which the result is CD

=Count(

{<Brand=
{
"\${=
Firstsortedvalue (Brand, -Aggr(Count({<Brand=>} Code), Brand), 2)
}"
}

>}

Aggr( Count(Distinct Code),Shop,Code))  // Result = 0

What am I doing wrong?

Thanks

1 Solution

Accepted Solutions
Contributor
Author

Hi,

I solved my problem using variables

=Count({<Brand={\$(vBrand2) } Brand)

Where vBrand2 was defined as a variable =Firstsortedvalue (Brand, -Aggr(Count({<Brand=>} Code), Brand), 2)

Thanks

3 Replies
Support (Former)

Hello,

Can you post a sample app with your expressions  for us to take a look at?

Digital Support

Maybe something like this:

=Count({<Brand= {"=\$(Firstsortedvalue (Brand, -Aggr(Count({<Brand=>} Code), Brand), 2))"}>}Aggr( Count(Distinct Code),Shop,Code))

To help users find verified answers, please don't forget to mark a correct resolution or answer to your problem or question as correct.
Contributor
Author

Hi,

I solved my problem using variables

=Count({<Brand={\$(vBrand2) } Brand)

Where vBrand2 was defined as a variable =Firstsortedvalue (Brand, -Aggr(Count({<Brand=>} Code), Brand), 2)

Thanks