Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Ranking by Groups for Sorting a Table
PaulCooper
<p>Using BIRT 3.7.2 I am trying to add an Rank field to a table and sort the data by it. The ranking is to be grouped too. Trying this I run into problems.</p>
<p> </p>
<p><em>(Deleted details of this post. I was being dumb and I can get round the issue by sorting by the field I used to rank on!)</em></p>
<p> </p>
<p>Regards</p>
<p> </p>
<p>Paul Cooper</p>
Find more posts tagged with
Comments
mwilliams
Glad you found a solution to your issue! Thanks for updating your thread. Let us know whenever you have questions.
PaulCooper
<p>One thing I did find as part of this was the limit in using aggregate filters in computed columns in the dataset:</p>
<p> </p>
<p>I would have like to use the current row's data such as:<br><br>
row["grouping_field"] == current_row["grouping_field"]</p>
<p>or</p>
<p> row["salary"] < current_row["salary"]<br><br>
If the "current_row" concept exists, however it is named or referenced, I can not find any mention of it. All I can use filters for is absolutes such as:<br><br>
row["salary"] > 30000<br><br>
Which is very limiting.</p>
<p> </p>
<p>Anyway to do this?</p>
<p> </p>
<p>Regards,</p>
<p> </p>
<p>Paul Cooper</p>
mwilliams
row["salary"] would be referencing the current row of the data set. Maybe I'm not understanding what you're trying to ask.
PaulCooper
<blockquote class="ipsBlockquote" data-author="mwilliams" data-cid="136002" data-time="1430926761">
<div>
<p>row["salary"] would be referencing the current row of the data set. Maybe I'm not understanding what you're trying to ask.</p>
</div>
</blockquote>
<p> </p>
<p>I can see why you think it is but that is not what I meant.</p>
<p> </p>
<p>Imagine I have a dataset that returns these four rows:</p>
<p> </p>
<p>Id Name Team Salary</p>
<p>1 John Smith US 45000</p>
<p>2 Jenny Jones US 50000</p>
<p>3 Brian Black Europe 32000</p>
<p>4 Joe Green Europe 23000</p>
<p> </p>
<p>If I add an aggregate Computed Column of "Count_Low_Salary" to the data set which is a Count with a Filter of row["Salary"] < 33000 I would get:</p>
<p> </p>
<p>Id Name Team Salary Count_Low_Salary</p>
<p>1 John Smith US 45000 2</p>
<p>2 Jenny Jones US 50000 2</p>
<p>3 Brian Black Europe 32000 2</p>
<p>4 Joe Green Europe 23000 2</p>
<p> </p>
<p>This is the same value per record.</p>
<p> </p>
<p>What I would like to do is be able to create an aggregate such as "Rank_By_Salary_By_Team" which is a Count with a filter of row["Salary"] < current_row["Salary"] && row["Team"] == current_row["Team"] which would give:</p>
<p> </p>
<p>Id Name Team Salary Rank_By_Salary_By_Team</p>
<p>1 John Smith US 45000 0</p>
<p>2 Jenny Jones US 50000 1</p>
<p>3 Brian Black Europe 32000 1</p>
<p>4 Joe Green Europe 23000 0</p>
<p> </p>
<p>So for the record with Id = 1 the aggregate "Rank_By_Salary_By_Team" it would use a filter of row["Salary"] < 45000 && row["Team"] == "US"; for the record with Id=3 the filter would be row["Salary"] < 32000 && row["Team"] == "Europe"; etc.</p>
<p> </p>
<p>This currently some of what can be done via the method I am describing above can be done using a table with groupings where you can create an aggregate in the Bindings but obviously this means you can only use one set of groupings. The other way is to use analytical functions in the SQL but this method can not use Computed Columns to aggregate on.</p>
<p> </p>
<p>I hope it is clearer what I mean now.</p>
<p> </p>
<p>Regards,</p>
<p> </p>
<p>Paul Cooper</p>
mwilliams
To do this in your data set (since there's no concept of grouping in a result set), you'd likely have to store the values of your original data set into an array or arrays and do your computations in a scripted data set. Or run your query through a connection you create in the beforeFactory method in script and store your result set in an array or arrays that you can use in your BIRT data set. In any fashion, if you don't do it in your query or in your grouped table, you'll have to pre-process your result set so that you can iterate the result set in your calculations for your aggregation/computed column.<br><br>Attached is an example of using a scripted data set. I put your original data in a csv file, so that's attached as well. Run the report design to see the scripted data set contents. The preview of the scripted data set won't work as it requires the original data set to be processed (why the hidden text box bound to "Data Set" is there).<br><br>Let me know if I'm still misunderstanding.