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: 
Anonymous
Not applicable

Only, aggr, rank in set analysis ?

Hi,

I 've got data like this  :

Table_Test_:

LOAD * INLINE [

ID, Year, Income, Expense

1 , 2014 , 987, 700

1 , 2015 , 1000, 900

1 , 2016 , 1100, 950

1 , 2017 , 1200, 900

2 , 2014 , 1800, 101

2 , 2015 , 2000, 1000

2 , 2016 , 1200, 50

2 , 2017 , 1900, 1700

3 , 2014 , 55, 1010

3 , 2015 , 900, 1000

3 , 2016 , 1200, 1050

3 , 2017 , 1210, 1070

4 , 2014 , 987, 986

4 , 2015 , 1111, 999

4 , 2016 , 1234, 955

4 , 2017 , 1212, 999

];

In a chart I've Year as dimension and Avg({$<Year=>}Income) & Avg({$<Year=>}Expense) as measures.

In the title I would like to have the year with the second % of exepense, the % of the expense and the % of the income.

For the 2 fisrt, that works fine, but i need help for the last one ...

='2nd Year less exp: ' & only(if(aggr(

Rank(sum(Expense)/Sum(Total Expense),Year)

        ,Year)=2,Year

           )

       )

       & ' with ' &

      

       round (max(aggr(sum(Expense)/Sum(Total Expense),Year),2) * 100, 0.1)    

      

       & '% expense and ' &

      

       sum({$<Year ={'only(if(aggr(

        Rank(sum(Expense)/Sum(Total Expense),Year)

                            ,Year)=2 ,Year))

                      '} >

        }Income)

            /

        Sum (Total {$<Year =>} Income) & '% income'

4 Replies
honeyasha
Contributor III
Contributor III

Hi Nicolas for the above expression what exactly you need.

shansundar
Partner - Creator
Partner - Creator

You can try using first sorted value like below,

firstsortedvalue (Year, Expense%, 2).

Thanks,

Shan S

Anonymous
Not applicable
Author

Hi,

It was not very clear ....

What i want in my title :

2nd year with more % of expense is 2015 whith 27.1% expense and 26.4% of income.

I can find the year, the 27.1% but i need help for the 26.4.

Thanks.

Anonymous
Not applicable
Author

I think, i found the answer,

a = was missing ...

='2nd Year less exp: ' & only(if(aggr(

Rank(sum(Expense)/Sum(Total Expense),Year)

        ,Year)=2,Year

          )

      )

      & ' with ' &

      round (max(aggr(sum(Expense)/Sum(Total Expense),Year),2) * 100, 0.1)  

      & '% expense and ' &

      sum({$<Year ={'=only(if(aggr(

        Rank(sum(Expense)/Sum(Total Expense),Year)

                            ,Year)=2 ,Year))

                      '} >

        }Income)

            /

        Sum (Total {$<Year =>} Income) & '% income'

thanks.