SSRS Interactive Sort Row Group data by Column Group - sorting

In SSRS I am attempting to do an interactive sort on the combination of a column group and a row group.
So my data would look like:
-------- ------------- --------- -------- -----------------
Category CampaignType Campaign Quarter Value
-------- ------------- --------- -------- -----------------
Cat 1 CampType1 Camp1 Q1 1
Cat 1 CampType1 Camp1 Q2 4
Cat 1 CampType1 Camp2 Q1 51
Cat 1 CampType2 Camp1 Q1 3
Cat 1 CampType2 Camp1 Q2 1
Cat 1 CampType2 Camp2 Q1 3
Cat 1 CampType2 Camp2 Q3 56
Cat 2 CampType1 Camp1 Q1 8
Cat 2 CampType1 Camp1 Q3 11
Cat 2 CampType1 Camp2 Q1 2
Cat 2 CampType2 Camp1 Q1 23
Cat 2 CampType2 Camp2 Q1 3
Cat 2 CampType3 Camp2 Q2 8
-------- ------------- --------- -------- -----------------
So I am grouping on the rows by:
-Category
---CampType
------Campaign
Grouping on the column by the row.
Getting the sum of the "Value" at the intersection of these two points.
Add some totals and we're done.
I would like to be able to sort the campaign value sums by quarter.
That, in my opinion seems like a reasonable request.
See below firstly what it looks like in designer and then an example:

Related

UNIX output displayed in one line in mail

My CSV file looks like this:
------------------------------
|file count 1 | 10 |
|file count 2 | 10 |
|total file count | 20 |
------------------------------
When I send the same data in mail it is displayed in single line.
file count 1 ... 10 file count 2 ... 10 total file count ... 20
Thanks.

Oracle: Validate input data with given data structure rules

I have table called data rules. Its given below with some explanation.
Data|GroupNum|GroupType|GroupMinOcc|GroupMaxOcc|DataStatus|DataMinOccWithinGroup|DataMaxOccurenceWithinGroup|IDX
ABC |GroupA |Mandatory| 1 | 1 | Mandatory| 1 | 1 |1
DEF |GroupB |Mandatory| 1 | 1 |Mandatory | 1 | 1 |2
GHI |GroupC |Mandatory| 1 | 1 |Mandatory | 1 | 1 |3
JKL |GroupD |Optional | 0 | 1 |Optional | 0 | 1 |4
FFF |Group1 |Optional | 0 | 1 |Mandatory | 1 | 1 |5
RRR |Group1 |Optional | 0 | 1 |Optional | 0 | 2 |6
MMM |Group2 |Optional | 0 | 2 |Mandatory | 1 | 1 |7
PPP |Group2 |Optional | 0 | 2 |Optional | 0 | 1 |8
CCC |Group3 |Optional | 0 | 2 |Optional | 0 | 2 |9
SSS |Group4 |Mandatory| 1 | 2 |Mandatory | 1 | 1 |10
TTT |Group4 |Mandatory| 1 | 2 |Mandatory | 0 | 2 |11
Let me explain you this data rules first.
1) A group can have multiple data records
Here as you can see GroupA is having only ABC data and Group 1 is having FFF and RRR data.
2) A group can be mandatory and optional. It means a group will appear definitely if its mandatory. Secondly If its mandatory, then its data records also having mandatory and optional status.
For example: Check group4
This group is mandatory and its First data SSS is also mandatory. It means this group is mandatory and when it will occur this data should also occur. But second data in this group is TTT which is optional. No matter group is mandatory, but this data is optional inside mandatory group so it can occur from 0 to 2 times
Lets Say this group occur two times..It would look like this
Group4 Example: Valid
SSS
TTT
TTT
SSS
TTT
Invalid Group4 occurrence
SSS
SSS
TTT
TTT
TTT
Its invalid because in second occurrence of group TTT is occurred 3 times but it should not exceed from 2
3) If group is optional it can be appear or cannot be.
So As you can see, GroupD, Group2 and Group3 are optional So after GroupC directly Group4 data also can come in input data..like this
ABC
DEF
GHI
SSS
TTT
I want to capture exact IDX number from Data rules table from their respective groups only, If input data dont follow the rules mentioned in data rules table.
For example 1st Input Data Example
ABC
DEF
GHI
JKL
JKL
SSS
As you can see here JKL is optional data in optional group. But if this optional group occurs this JKL should come only one time. But it came twice. So I want return that IDX number 4.
2nd Data Example.
ABC
DEF
GHI
TTT
Here it should return IDX number 10. Because from mandatory group4 mandatory data SSS is missing and in data rules its IDX is 10
3rd Example
ABC
DEF
GHI
SSS
SSS
TTT
In this also IDX return for SSS should be 10. Because Its occurred twice. And as you can see in data rules whole Group4 can repeat one time only and whenever it will occur SSS will come only one time. SO that's a error
Many errors can occur same time as well. SO IDX number needs to returned from their respective group data only from data rules table.
In input data, Only one column will come with data records only.
Note: Group data will appear only in series like mentioned in data rules from top to bottom. And can be appeared or not on the basis of definition mentioned in data rules table.
Any suggestions..how can I achieve this ?

Emit a group only when condition meets

I have requirement to emit all records corresponds to a group, only when a condition is met. Below is the sample data set with alias name as "SAMPLE_DATA".
Col-1 | Col-2 | Col-3
-------------------------
2 | 4 | 1
2 | 5 | 2
3 | 3 | 1
3 | 2 | 2
4 | 5 | 1
4 | 6 | 2
SAMPLE_DATA_GRP = GROUP SAMPLE_DATA BY Col-1;
RESULT = FOREACH SAMPLE_DATA_GRP {
max_value = MAX(SAMPLE_DATA.Col-2);
IF(max_value >= 5)
GENERATE ALL RECORDS IN THAT GROUP;
}
RESULT should be:
Col-1 | Col-2 | Col-3
-------------------------
2 | 4 | 1
2 | 5 | 2
---- ---- ---
4 | 5 | 1
4 | 6 | 2
Two groups got generated. First group is generate because max value of 4,5 is "5"(which meets our condition >=5). Same for second group (6 >= 5).
As I would be performing this operation on big dataset operations like distinct and join would be overkill. For this reason I have come up with pseudo code with one grouping to perform this operation.
Hope I have provided enough information. Thanks in advance.
I would be performing this operation on a huge data set. Doing operation like distinct and join would be overkill on the system. For this reason I have come up with this grouping approach.
Please try the below code and see..
This solution is little lengthy ,but it will work
numbers = LOAD '/home/user/inputfiles/c1.txt' USING PigStorage(',') AS(c1:int,c2:int,c3:int);
num_grp = GROUP numbers by c1;
num_each = FOREACH num_grp
{
max_each = MAX(numbers.c2);
generate flatten(group) as temp_c1, (max_each >= 5 ?1 :0) as indicator;
};
num_each_filtered = filter num_each BY indicator == 1;
num_joined = join numbers BY c1,num_each_filtered by tem_c1;
num_output = FOREACH num_joined GENERATE c1,c2,c3;
dump num_output;
O/p:
Col-1 | Col-2 | Col-3
-------------------------
2 | 4 | 1
2 | 5 | 2
---- ---- ---
4 | 5 | 1
4 | 6 | 2

Oracle hierarchical query join to selection of all decendants

I am trying to retrieve a list of each descendant with each item.
I am not sure I am making sense, I will try and explain.
Example Data:
ID | PID
--------
1 | 0
2 | 1
3 | 1
4 | 1
5 | 2
6 | 2
7 | 5
8 | 3
etc...
The desired results are:
ID | Decendant
--------------
1 | 1
1 | 2
1 | 3
1 | 4
...
2 | 2
2 | 5
2 | 6
2 | 7
3 | 3
3 | 8
etc...
This is currently being achieved by using a cursor to move through the data and inserting each descendant into a table and then selecting from them.
I was wondering if there was a better way to do these, there must be a way to right a query that would bring back the desired results.
If any one has ideas, or has figured this out before it would be very appreciated. Ordering is not important, nor is the 1 - 1, 2 -2 reference. It would be cool to have it, but not crucial.
select connect_by_root(id) as ID, id as Decendant
from table1
connect by prior id = pid
order by 1, 2
fiddle
Here is my attempt! Not sure, if I got you right!
select pid ,connect_By_root(id) as descendant from process
connect by id = prior pid
union all
select distinct pid,pid from
process
order by pid,descendant

Selecting greatest value of B for equal entries in A

Consider the following table:
A | B
-----|------
123 | 1
456 | 2
123 | 5
456 | 0
789 | 3
789 | 9
123 | 6
I want to get the following output:
A | B
-----|------
123 | 6
456 | 2
789 | 9
In other words: the greatest value of B for each equal value in A.
The initial table above comes already from another query which only selects duplicates of A:
select A, B from tbl where A in (
select A from tbl
group by A
having count(A) > 1
);
I tried wrapping/integrating another grouping function with and without max(B) around/into this query, but no success.
How can I get the desired output?
Just use max:
select A, max(B)
from tbl
group by A
having count(A) > 1
maybe I'm being naive here, but:
SELECT tbl2.A, MAX(tbl2.B) FROM
(select A, B from tbl where A in (
select A from tbl
group by A
having count(A) > 1
)) as tbl2
GROUP BY tbl2.A
seems like it should work.

Resources