Sum up custom grand total on crosstab in BIRT - birt

I have a crosstab and create custom grand total for the row level in each column dimension, by using a data element expression.
Crosstab Example:
Cat 1 Cat 2 GT
ITEM C F % VALUE C F % VALUE
A 101 0 0.9 10 112 105 93.8 10 20
B 294 8 2.7 6 69 66 95.7 10 16
C 211 7 3.3 4 212 161 75.9 6 10
------------------------------------------------------------------
GT 606 15 2.47 6 393 332 84.5 8 **14**
Explanation for GT row:
Those C and F column is summarized from the above. But the
% column is division result of F/C.
Create a data element to fill the VALUE column, which comes from range of value definition, varies for each Cat (category). For instance... in Cat 1, if the value is between 0 - 1 the value will be 10, or between 1 - 2 = 8, etc. And condition for Cat 2, between 85 - 100 = 10, and 80 - 85 = 8, etc.
The GT row (with the value of 14), is gathered by adding VALUE of Cat 1 + Cat 2.
I am able to work on point 1 and 2 above, but I can't seem to make it working for GT row. I don't know the code/expression to sum up the VALUE data element for this 2 categories. Because those VALUE field comes from one data element in design mode.

I have found the solution for my problem. I can show the result by using a report variable. I am assigning 2 report variables in % field expression, based on the category in data cube dimension (by using if statement). And then in data element expression, I am calling both of the expressions and add them.

Related

Report Builder Expressions Help Sum three fields then divide by 5

I currently have three columns in report builder that look like this.
PU PI LO Total SUM
0 13 31 44
The Total Sum column is an expression that sums the first three columns with =Fields!Put_Away.Value+Fields!Picked.Value+Fields!Loaded.Value. I now want to create one more column that grabs the sum of of those three fields and divides it by 5. How do I do this? I tried =Fields!PU.Value+Fields!PI.Value+Fields!LO.Value/5 but it gives me 19.2 as the result of the example above.
You need to use brackets.
Currently you are doing =Fields!Put_Away.Value+Fields!Picked.Value+Fields!Loaded.Value/5, which converts to 0 + 13 + 31 / 5, or if we include the inferred brackets, 0 + 13 + (31/5).
You want =(Fields!Put_Away.Value+Fields!Picked.Value+Fields!Loaded.Value)/5, which becomes (0 + 13 + 31)/5

Make a matrix B of the first, fourth and fifth row and the first and fifth column from matrix A in OCTAVE

I have matrix A
A =
5 10 15 20 25
10 9 8 7 6
-5 -15 -25 -35 -45
1 2 3 4 5
28 91 154 217 280
And i need to make a matrix B of the first, fourth and fifth row and the first and fifth column from matrix A.
How can i do it?
>> B = A([1,4,5],[1,5])
B =
5 25
1 5
28 280
You should look up how to use index expressions in the Matlab and Octave language to extract and work with submatrices.
See the Octave help on Index expressions: https://octave.org/doc/latest/Index-Expressions.html

Lexicographical sorting of matrix

I'm required to sort the matrix(each row is a feature vector) in lexicographical order.
test_mat = [10 40 30 -1 ; 43 78 -5 1; 87 54 -4 -2];
But after looking at several posts, there are:
sortrows(test_mat)
sort(test_mat)
I'm not entirely sure which method is right, as I'm getting quite different results from each.
According to Sardar Usama's comment I'm using the test matrix:
A = [10 40 30 -1;
43 78 -5 1;
87 54 -4 -2];
sort(A,dim) sorts every vector of A in ascending order. If dim is 1, then every column vector, if dim is 2 then ever row vector.
E.g.:sort(A, 2)sorts every row of A in ascending order. This means that every row will be considered a row vector and will be sorted in ascending order.
% ascending sorting of every row vector
sort(A,2)
ans =
-1 10 30 40
-5 1 43 78
-4 -2 54 87
% ascending sorting of every column vector
sort(A,1)
ans =
10 40 -5 -2
43 54 -4 -1
87 78 30 1
sortrows(A, col) sorts the rows of A in ascending order according to the column col. The individual rows don't change, so the rows are not modified.
E.g.:sortrows(A,1)won't change A at all, since the first column is already in ascending order.
sortrows(A,1)
ans = 10 40 30 -1
43 78 -5 1
87 54 -4 -2
If you just use sortrows(A), A will always be sorted according to the first column by default, if you use sortrows(A,1), it does therefore the same thing, but you could also use sortrows(A,3) and sort according to the 3rd column. Additionally you can also use sortrows(A,[1 3]), which sorts first based on column 1 and all rows where column 1 has the same value will be sorted according to column 3. sortrows(A,[1 2 3 4]) is of course the same as sortrows(A). (thats the default)
So if your rows are feature vectors, sortrows will order your feature vectors according to one of the features/columns, but the feature vectors/rows itself will stay unchanged and sort will also change the rows/feature vectors itself, since every row will be changed/sorted in ascending order. So I guess you want sortrows.
If you only have numeric values, I don't see any reason for casting.

gnuplot give wrong results from stats matrix

Suppose that I have the file data.dat with follow content:
Days 1 2 4 6 10 15 20 30
Group 01 37.80 30.67 62.88 86.06 26.24 98.49 65.42 61.28
Group 02 38.96 72.99 38.24 74.11 39.54 91.59 81.14 91.22
Group 03 82.34 75.25 82.58 28.22 39.21 81.30 41.30 42.48
Group 04 75.52 42.83 66.80 20.50 94.08 74.78 95.09 53.16
Group 05 89.32 56.78 30.05 68.07 59.18 94.18 39.77 67.56
Group 06 70.03 78.71 37.59 60.55 46.40 82.73 67.34 93.38
Group 07 67.83 88.73 48.01 62.19 49.40 67.68 25.97 58.98
Group 08 61.15 96.06 59.62 39.42 60.06 94.18 76.06 32.02
Group 09 65.61 72.39 54.07 92.79 56.58 39.14 81.81 39.16
Group 10 59.65 77.81 40.51 68.49 66.15 80.33 87.31 42.07
The final intention is create a histogram using histogram clustered.
Besides the graph, I need of some values from data.dat such as
size_x, size_y, min, max, and mean. To achieve the last task I used
set datafile separator tab
stats 'data.dat' skip 1 matrix
The summed up output was:
* MATRIX: [9 X 10]
Minimum: 0.0000 [ 0 0 ]
Maximum: 98.4900 [ 6 0 ]
Mean: 56.0549
The size_x and size_y values are correct – 9 columns and 10 rows – but the min is not.
This is due to the fact that the first column is string-type.
When I include every
set datafile separator tab
stats 'data.dat' skip 1 matrix every ::1
to skip the first column, the summed up output is:
* MATRIX: [9 X 8]
Minimum: 20.5000 [ 0 3 ]
Maximum: 98.4900 [ 5 0 ]
Mean: 63.0617
This time the min and max values are right, but the size_y (shown 8, expected 9) and index from min (expected [ 3 3 ]) is not.
What is going on? I made some mistake? I'm not noticing something?
The program tries to read a value from the first field of each row, sees "Group xx" and ends up filling in 0 for that entry. You need to tell it to skip the first column.
Amended answer
I think there is a bug here, as well as confusion between documentation and the actual implementation. The matrix rows and columns as implemented by the every selector are indexed from 0 to N-1 as they would be for C language arrays. The documentation incorrectly states or at least implies that the first row and column is matrix[1][1] rather than [0][0]. So the full command needed for your case is
gnuplot> set datafile sep tab
gnuplot> stats 'data.dat' every 1:1:1:1 matrix
warning: matrix contains missing or undefined values
* FILE:
Records: 80
Out of range: 0
Invalid: 0
Header records: 0
Blank: 10
Data Blocks: 1
* MATRIX: [9 X 8]
Mean: 63.0617
Std Dev: 20.6729
Sample StdDev: 20.8033
Skewness: -0.1327
Kurtosis: 1.9515
Avg Dev: 17.4445
Sum: 5044.9400
Sum Sq.: 352332.2181
Mean Err.: 2.3113
Std Dev Err.: 1.6343
Skewness Err.: 0.2739
Kurtosis Err.: 0.5477
Minimum: 20.5000 [ 0 3 ]
Maximum: 98.4900 [ 5 0 ]
I.e. every 1:1:1:1 tells it for both rows and columns the index increment is 1 and the submatrix starts at [1][1] rather than at the origin [0][0].
The output values are all correct, but the indices shown for the size [9 x 8] and the min/max entries are wrong. I will file a bug report for both issues.
I got sidetracked trying to characterize the bug revealed by the original answer and forgot to mention a simpler alternative. For this specific case of one row of column headers and one column of rowheaders, gnuplot provides a special syntax that works without error:
set file separator tab
stats 'data.dat' matrix rowheaders columnheaders

MATLAB: finding a row index in a matrix

I have a matrix and I want to find the maximum value in each column, then find the index of the row of that maximum value.
A = magic(5)
A =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
[~,colind] = max(max(A))
colind =
3
returns colind as the column index that contains the maximum value. If you want the row:
[~,rowind] = max(A);
max(rowind)
ans =
5
You can use a fairly simple code to do this.
MaximumVal=0
for i= i:length(array)
if MaximumVal>array(i)
MaximumVal=array(i);
Indicies=i;
end
end
MaximumVal
Indicies
Another way to do this would be to use find. You can output the row and column of the maximum element immediately without invoking max twice as per your question. As such, do this:
%// Define your matrix
A = ...;
% Find row and column location of where the maximum value is
[maxrow,maxcol] = find(A == max(A(:)));
Also, take note that if you have multiple values that share the same maximum, this will output all of the rows and columns in your matrix that share this maximum, so it isn't just limited to one row and column as what max will do.

Resources