COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: inu on 26 Feb 2014 09:41:53 PM

Title: How to sort a data item dynamically
Post by: inu on 26 Feb 2014 09:41:53 PM
Hi
There is scenario i got, where
1. two prompts are there in report page each with ascending / descending options
2. two colums say country, city

but i m not able to solve the problem. sending the screenshot, please go through it , and help me out.

Regards
Inam
Title: Re: How to sort a data item dynamically
Post by: Francis aka khayman on 26 Feb 2014 09:46:09 PM
You never stated your problem  :P
Title: Re: How to sort a data item dynamically
Post by: BigChris on 27 Feb 2014 02:15:52 AM
I think I can see what you're getting at, but I'm not sure how to solve it for you. It looks like you want to conditionally sort asc / desc on Country, followed by asc / desc on City. I can do that with numeric fields, but I'm not sure how to achieve it for alphanumeric fields.
Title: Re: How to sort a data item dynamically
Post by: navissar on 27 Feb 2014 03:09:48 AM
Chris, you're on the right track, what you're missing is the fact that a rank function will in fact rank string alphabetically.
So, here's a step by step:
1. You want to create a data item that would be your "sort item". Call it "Country_Sort_Item". The expression is
rank([country] #prompt('countryDir','token','asc')#)
This expression will take the value from the sort prompt (Default to asc).
2. Highlight the list, in Properties Pane under Data find "Grouping and sorting". Drag your Coutry_Sort_Item to the sort list folder under the "Country" group.
You're basically done. The prompt will pass on "Asc" or "Desc" to the rank function which will do the sorting.
Repeat for city.
Title: Re: How to sort a data item dynamically
Post by: adik on 27 Feb 2014 03:12:26 AM
i have two sollutions for you:
1.
you either create 4 lists sorted by each combination: coutry ascending + city ascending / country ascending + city descending ...
you then create variables and based on selection you render one of the lists

this is not a very clean and mantanable sollution but will get the job done

2.
create 4 query items with the following formulas:
[Country ASC]
rank([Country] ASC at [Country])

[Country sort]
case
when ?p_country_sort? = 'ascending' then [Country ASC]
when ?p_country_sort? = 'descending' then (-1 * [Country ASC])
end


[City ASC]
rank([City] ASC for [Country])

[City sort]
case
when ?p_city_sort? = 'ascending' then [City ASC]
when ?p_city_sort? = 'descending' then (-1 * [City ASC])
end


in your list place both [Country sort] and [City sort], sort the list by the 2 query items ascending and set the box property for the 2 columns to none
?p_country_sort? and ?p_city_sort? are you parameters for the sorting selection, make them autosubmit
Title: Re: How to sort a data item dynamically
Post by: mitwa on 28 Feb 2014 05:36:24 AM
1st method:

just create two list in one page..make one list as ascending usins sort option and another as descending then write one string variable..

case when ParamDisplayValue('asc/dsc')='asc' then 'show' else 'hide' end

like this show 1st list wen asc and 2nd list wen dsc..

thts it..better and simple way

2nd method

using static choice assign 1 as asc & 2 as dsc

then create dataitem1 in d query as  Case when  ?asc/dsc?= 1 then [city]  end
                    dataitem2 in d query as  Case when  ?asc/dsc?= 2 then [city]  end

thts it...

3rd method

do as tht as above bt drop tht dataitem1 and 2 inside d city in list page..


these all will help u ;)