COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: JuliaM on 11 May 2015 10:15:36 AM

Title: Dynamic sorting of 3 columns of the list
Post by: JuliaM on 11 May 2015 10:15:36 AM
Hi!
I have a list report with 3 numeric columns (sales figures for customers) and 3 columns with calculations based on sales figures. I added 3 prompts for each calculated column header with static selection (0=Do not sort, 1=Sort ascending, -1=Sort Descending).

The problem I have is - if one of the prompts is used, the other two need to be 0=Do not sort, and I can't figure out how to set them automatically.

Thank you for helping!
Title: Re: Dynamic sorting of 3 columns of the list
Post by: Francis aka khayman on 12 May 2015 01:42:31 AM
is your problem in the sorting? or the setting of values in the prompt?
Title: Re: Dynamic sorting of 3 columns of the list
Post by: BigChris on 12 May 2015 03:22:43 AM
I'm not sure how you've set your report up, but the sort of approach I've used before is to have a single prompt, called pSortField,  with 3 static choices, 1 for each column that you're going to sort on. Then in your query I've created a calculated field called SortField, which looks something like:

CASE ?pSortField?
  when 'Column1' then [Query].[Column1]
  when 'Column2' then [Query].[Column2]
  when 'Column3' then [Query].[Column3]
Else NULL
END


Then just sort your report by SortField.
Title: Re: Dynamic sorting of 3 columns of the list
Post by: JuliaM on 12 May 2015 10:01:04 AM
Hi!
Thank you for answering.
I initially set the first prompt to 1=Sort Ascending, the second to 0=Do not sort.
The first one works fine. I'd like to set the first one to 0=Do not sort if the second one is used.
Sorting by the second one is not working properly either, I think.

If I use one prompt for the report (I actually need three columns sorted), will it sort ascending/descending automatically?

Title: Re: Dynamic sorting of 3 columns of the list
Post by: BigChris on 12 May 2015 10:27:30 AM
Looking at your data it looks like you're sorting on numeric data, which makes things much simpler. If you follow what I suggested earlier, you would then need a second prompt to allow the user to choose ascending or descending. I'd call that second prompt SortDirection. in your prompt page, or at the top of your report if that's where you're going to put the options, you'd have the first prompt with three static choices, and a second prompt with two static choices. Your SortField would then look something like:
CASE ?pSortField?
  when 'Column1' then [Query].[Column1]
  when 'Column2' then [Query].[Column2]
  when 'Column3' then [Query].[Column3]
Else NULL
END
*
CASE ?pSortDirection?
  when 'Ascending' then 1
  when 'Descending' then -1
  Else NULL
END
Title: Re: Dynamic sorting of 3 columns of the list
Post by: JuliaM on 12 May 2015 11:05:17 AM
I would need 2 sort fields then? In my query?
Title: Re: Dynamic sorting of 3 columns of the list
Post by: BigChris on 13 May 2015 01:59:01 AM
No, just one field, but two prompts. The code that case for one field - there's a multiplication in the middle of it.