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: 
shamitshah
Partner - Creator
Partner - Creator

Count function

Hi,

I am trying to count the number of items that are doing better compared to the previous year. I have two variables set up as follows which shows the total sales for the respective years:

v1)=num(sum(AGGR(SUM({<FiscalYear={2016}>}SLL_PriceExc),[Item Number])),'#.')

v2)= num(sum(AGGR(SUM({<FiscalYear={2015}>}SLL_PriceExc),[Item Number])),'#.')

I tried to use the following formula but it did not give any results:

=num(Count(DISTINCT( if (v1>v2,[Item Number]))))

Any ideas?

Thanks

Shamit

1 Solution

Accepted Solutions
Gysbert_Wassenaar

Try =Count({<Item={"=sum({<Year={2016}>}Sales)>sum({<Year={2015}>}Sales)"}>}DISTINCT Item)


talk is cheap, supply exceeds demand

View solution in original post

10 Replies
Chanty4u
MVP
MVP

=sum(agg(Count(

if (v1>v2,

DISTINCT[Item Number]))))

sunny_talwar

Can you change your variable to this:

v1 = Aggr(Sum({<FiscalYear={2016}>}SLL_PriceExc),[Item Number])

v2 = Aggr(Sum({<FiscalYear={2015}>}SLL_PriceExc),[Item Number])

and then try this:

Count(DISTINCT(If(v1 > v2, [Item Number]))


Have not tested it out, so not 100% sure if this is going to work or not


Chanty4u
MVP
MVP

=num(Count(DISTINCT( if (v1>v2,[Item Number]))),'#.')

shamitshah
Partner - Creator
Partner - Creator
Author

Hi Sunny & Chanty

I tried what you mentioned above, but is does not seem to work.

Thanks

Shamit

sathishkumar_go
Partner - Specialist
Partner - Specialist

post your application with sample data

-Sathish

sunny_talwar

Can you share a sample?

shamitshah
Partner - Creator
Partner - Creator
Author

Hi,

Please see attached file.

The number of items with a positive variance in the text box should be 1 instead of 3.

Thanks

Shamit

Gysbert_Wassenaar

Try =Count({<Item={"=sum({<Year={2016}>}Sales)>sum({<Year={2015}>}Sales)"}>}DISTINCT Item)


talk is cheap, supply exceeds demand
sunny_talwar

You can apply Gysbert's logic with variables also:

=Count({<Item={"=$(v1)>$(v2)"}>}DISTINCT Item)

Where v1 is defined as 'Sum({<Year={2016}>}Sales)' and v2 is defined as 'Sum({<Year={2015}>}Sales)'

Capture.PNG