Sum calculated rows and columns

I have written a SQL report to count the number of offenses by levels of disciplinary actions.  Now I want to total
the counts for the rows and columns.  How do I do this? Below is my code.  It produces column headings with counts.  Ie.
Offense Description   Level I  Level II  Susps Terms
2 Minor Violations      0         1       
0    0  
SELECT
UPPER(DESCRIPTION) as OFFENSE,
SUM(CASE
WHEN OUTCOME = 'LEVEL I'
THEN 1
ELSE 0
END) as LEVELI,
SUM(CASE
WHEN OUTCOME = 'LEVEL II'
THEN 1
ELSE 0
END) as LEVELII,
SUM(CASE
WHEN OUTCOME = 'SUSPEND'
THEN 1
ELSE 0
END) as SUSPEND,
SUM(CASE
WHEN OUTCOME = 'TERM'
THEN 1
ELSE 0
END) as TERM
FROM
PAGRDI
Where
R_DATE >= '2014-01-01' and R_DATE <= '2014-01-31'
Group by
DESCRIPTION
Order by
OFFENSE

Hi Wildcatgirl,
According to your description, you have used T-SQL to get the counts for different OUTCOME. Now you want to get the total for each OFFENSE and OUTCOME. Right?
In this scenario, since you have already get those counts with T-SQL query, so in your dataset it will have data fields below: OFFENSE, LevelI, LevelII, SUSPEND, TERM. We just need to drag these data fields into a table, add a column at the end of the table
and use expression to sum the counts for different OUTCOME. Then we can add a total for the detail row. We have tested this scenario in our local environment. Here are screenshots for your reference:
Reference:
Tables (Report Builder and SSRS)
If you have any question, please feel free to ask.
Best Regards,
Simon Hou

Similar Messages

  • Summing the Rows and Columns in an Array

    I am importing a 2-dimensional array of integers.(which is held in a 2-dimensional array)
    I need to store the row sums and column sums in separate 1-dimensional arrays.
    I can get the integers in and print out a list along with the grand total(sum of all).
    But, how do I pass each row's and each column's value in to my sumRow and sumCol methods to get the sum for each row and each column?
    Can I do the row and column summing in the same "for" statement where I calculate the "grand total"? Or am I making this more difficult than it is?
    Would appreciate any help.
    This is what I have so far:
    import java.awt.Graphics;
    import java.applet.Applet;
    public class TwoWayTable extends Applet {
         int numRows;
         int numCols;
         int [] [] cell;
         int [] rowSum;
         int [] colSum;
         int grandTotal;
    public TwoWayTable(int [][] data){
    grandTotal = 0;
    cell = new int [data.length][data.length];
    for(int i = 0; i < data.length; i++)
    for(int j = 0; j < data.length; j++){
         cell[i][j] = data[i][j];
    grandTotal += cell[i][j];
         System.out.println(cell[i][j]);
    System.out.println(grandTotal);
    public int sumRow(int [] data2){
         int rowaccumulator=0;
         rowSum = new int[data2.length];
         for(int numRows = 0; numRows < rowSum.length; numRows++){
         rowaccumulator += rowaccumulator + rowSum[numRows];
              return(rowaccumulator);
    public int sumCol(int [] data3){
         int colaccumulator = 0;
         colSum = new int[data3.length];
         for(int numCols = 0; numCols < colSum.length; numCols++){
              colaccumulator += colaccumulator + colSum[numCols];
              return(colaccumulator);

    Thanks for your input.
    I'll make the changes that you suggest.(after this)
    My output prints:
    4 6 3 8 21
    9 1 5 3 18
    13 7 8 11 39
    numbers are right, but I need to format the table
    the output needs to look like this:
    int int int int | rowsum
    int int int int | rowsum
    colsum colsum colsum colsum | total
    How do I do this?
    I have no idea?
    I'm supposed to call a "void setMargins( )" method to line this up, without
    using the exotic formatting in the IO library.
    I'm also supposed to use "public String toString( )"
    This is what I have so far:
    import java.awt.Graphics;
    import java.applet.Applet;
    public class TwoWayTable extends Applet {
    int numRows;
         int numCols;
         int [] [] cell;
         int [] rowSum;
         int [] colSum;
         int grandTotal;
    public TwoWayTable(int [][] data){
    cell = new int [data.length][data.length];     
    for(int i = 0; i < data.length; i++){
    for(int j = 0; j < data.length; j++){
         cell[i][j] = data[i][j];
    calcTotals(cell);
    for(int i = 0; i < cell.length; ++i){
    for(int j = 0; j < cell.length; ++j){
    System.out.print(cell[i][j] + " ");
    System.out.println(rowSum[i] + " ");
    for(int j = 0; j < cell.length-1; ++j){
    System.out.print(colSum[j] + " ");
    System.out.println(colSum[cell.length-1] + " " + (grandTotal));
         public void calcTotals(int [][] data2){
              grandTotal = 0;
              rowSum = new int[data2.length];                         
              colSum = new int[data2.length];                         
              for(int numRows = 0; numRows < data2.length; numRows++){
              for(int numCols = 0; numCols < data2.length; numCols++){
                   grandTotal += data2[numRows][numCols];               
                   rowSum[numRows] += data2[numRows][numCols];
                   colSum[numCols] += data2[numRows][numCols];

  • Table -- sum of rows and columns?

    I was wondering if anyone has a suggestion to how I can easily generate the sum of each row and column in a two dimensional table? This is what I've got so far:
    public class SumRowsColumns {
        public static void main (String[] args) {
         int[][] table = new int[2][3];
         // gets the values
         for (int i = 0; i < table.length;
              i++) {
             for (int j = 0; j < table.length;
              j++)
              table[i][j] = Terminal.lesInt(); // Terminal is a class that can read the terminal input
         System.out.println("\t\t\t\tSum:");
         // prints the values
         for (int i = 0; i < table.length;
         i++) {
         for (int j = 0; j < table[i].length;
              j++) {
              System.out.print("\t" + table[i][j]);
         System.out.println();
         // sum of first column
         int sumColumn = 0;
         for (int i = 0; i < table.length;
         i++) {
              sumColumn += table[i][0];
         System.out.print("\nSum:\t");
         System.out.println(sumColumn);
    Example of output:
    1
    2
    3
    4
    5
    6
                                    Sum:
            1       2       3
            4       5       6
    Sum:    5This is the output I'd like:
    1
    2
    3
    4
    5
    6
                                    Sum:
            1       2       3     6
            4       5       6     15
    Sum:    5     7     9One way of getting the sum for all the columns is to make a for-loop for each one of them, but there has to be a better way. I could apply the same hack to get the sum of the rows, but I still wouldn't know how to get the layout I want.

    After many hours of frustration I finally solved it (for-loops can be confusing, man) after I got a hint from a post in another forum: http://www.linuxquestions.org/questions/showthread.php?postid=624021#post624021
    A more logical name to the integers actually helped a lot too. And here's the final product:
    public class SumRowsColumns {
        public static void main (String[] args) {
         int[][] table = new int[2][3];
         // gets the values
         for (int row = 0; row < table.length;
              row++) {
             for (int col = 0; col < table[row].length;
               col++)
              table[row][col] = Terminal.lesInt(); // Terminal is a class that reads the terminal input
         System.out.println("\t\t\t\tSum:");
         // prints the values and sum of each row
         for (int row = 0; row < table.length;
              row++) {
             for (int col = 0; col < table[row].length;
               col++) {
              System.out.print("\t" + table[row][col]);
             int sum = 0;
             for (int col = 0; col < table[0].length;
               col++) {
              sum += table[row][col];
             System.out.println("\t" + sum);
         System.out.print("\nSum:");
         // sum of each column
         for (int col = 0; col < table[0].length; // table[0].length is the length of row 0 (the number of columns)
              col++) {
             int sum = 0;
             for (int row = 0; row < table.length; // table.length is the number of rows
               row++) {
              sum += table[row][col];
             System.out.print("\t" + sum);
         System.out.println();
    }

  • Sumproduct row and column?

    hello --
    it seems fairly straight forward to use sumproduct for two columns or two rows of a given length. how can i do the same for a row and a column of the same length. i keep getting an error when i do that. do i need to use a different function to get the desired result? basically what i am trying to do it:
    sumproduct((A1:A5),(C1:C5))
    thank you in advance for your help.

    The arguments to the sumproduct() function require the same dimensions.  I think this mean the same number of rows and columns.  Therefore a range from A1 to A5 is 5 rows , 1 column, whereas a range from C1 thru C5 is 1 row and 5 columns.
    I suggestion something like this to make the range in the C1 thru C5 reside in B1 thru B5:
    Now you can perform the sum product on column A and B.
    B1=OFFSET($C$1, 0, ROW()−1)
    this is shorthand for select cell B1, then type (or copy and paste from here) the formula:
    =OFFSET($C$1, 0, ROW()−1)
    select cell B1, copy,
    select cells B1 thru B5, paste
    For this example:
    D3=SUMPRODUCT(A, B)

  • Select row and column from header in jtable

    hello i have a problem to select row and column from header in jtable..
    can somebody give me an idea on how to write the program on it.

    Hi Vicky Liu,
    Thank you for your reply. I'm sorry for not clear question.
    Answer for your question:
    1. First value of Open is item fiels in Dataset2 and this value only for first month (january). But for other month Open value get from Close in previous month.
    * I have 2 Dataset , Dataset1 is all data for show in my report. Dataset2 is only first Open for first month
    2. the picture for detail of my report
    Detail for Red number:
    1. tb_Open -> tb_Close in previous month but first month from item field in Dataset2
    espression =FormatNumber(Code.GetOpening(Fields!month.Value,First(Fields!open.Value, "Dataset2")))
    2. tb_TOTAL1 group on item_part = 1
    expression =FormatNumber(Sum(CDbl(Fields!budget.Value)))
    3. tb_TOTAL2 group on item_part = 3 or item_part = 4
    expression =FormatNumber(Sum(CDbl(Fields!budget.Value)) + ReportItems!tb_TOTAL1.Value )
    4. tb_TOTAL3 group on item_part = 2
    expression =FormatNumber(Sum(CDbl(Fields!budget.Value)) - ReportItems!tb_TOTAL2 .Value)
    5. tb_Close -> calculate from tb_TOTAL3 - tb_Open
    expression =FormatNumber(Code.GetClosing(ReportItems!tb_TOTAL3.Value,ReportItems!tb_Open.Value))
    I want to calculate the value of tb_Open and tb_Close. I try to use custom code for calculate them. tb_close is correct but tb_Open is not correct that show value = 0 .
    My custom code:
    Dim Shared prev_close As Double
    Dim Shared now_close As Double
    Dim Shared now_open As Double
    Public Function GetClosing(TOTAL3 as Double,NowOpening as Double)
        now_close = TOTAL3 + NowOpening
        prev_close = now_close
        Return now_close
    End Function
    Public Function GetOpening(Month as String,NowOpen as Double)
        If Month = "1" Then
            now_open = NowOpen
        Else    
            now_open = prev_close
        End If
        Return now_open
    End Function
    Thanks alot for your help!
    Regards
    Panda A

  • Suppress Overall result (both rows and columns side and its data)

    Hello all,
    I need to do some settings in BEx Query Designer, so that In BEx Analyzer, I don't see 'overall result' both on 'rows' and 'column' sides
    This is what I have done so far
    In 'rows' section, Properties of my KF (no. Products) then 'calculation' tab 'calculate result as'=Suppress result
    This way in BEx Analyzer I don't see the FIGURES/DATA for 'Result' and 'overall result' BUT 'result' and 'overall result' still exist both on rows and colum side even if there are not figures in them.
    Is there any property in BEx Designer so that I don't see 'overall result' at all
    Best regards
    Ahmad

    thanks for responding
    selecting a characteristic, properties, Display tab, Result lines: Always Suppress
    with this I don't see 'result'
    but 'overall result' result exist both on 'rows' and 'column' side alongwith its data.
    If I combine the above with this: selecting KF, properties, calucations, Calculate result as: Suppress result
    then
    I don't see the data in 'overall result' BUT 'overall result' still exist both on rows and column sides
    any setting so that 'overall result' completely vanishes
    Best regards
    Ahsan

  • How can i open a PDF bank statement in numbers so that the rows and columns contain properly aligned data from statement?

    how can i open a PDF bank statement in "numbers" so that the rows and columns contain properly aligned data from statement?

    Numbers can store pdfs pages or clippings but does not directly open pdf files.  To get the bank statement into Numbers as a table I would open the bank statment in Preview (or Skim) or some pdf viewer.
    Then hold the option key while selecting a column of data.
    Then copy
    Then switch to numbers and paste the column into a table
    Then repeat for the other columns in the pdf document
    It would be easier (in my opinion) to download the QFX or CSV version from your bank

  • How to get number of rows and columns in a two dimensional array ?

    Hello,
    What would be the simplest way to get number of rows and columns in a two dimensional array represented as integers ?
    I'm looking for another solution as For...Each loop in case of large arrays.
    Regards,
    Petri

    Hi Petri,
    See a attached txt file for obtaining two arrays with upper and lower index values
    Regards
    Ray
    Regards
    Ray Farmer
    Attachments:
    Get2DArrayIndex.txt ‏2 KB

  • How do I delete multiple rows and columns in an image?

    I am looking into how digital SLRs extract video data from a CMOS sensor. To give an example, the GH1 from Panasonic can record video at 1920 x 1080 from a 12 MPixel sensor that, say, is 4000 horizontal x 3000 vertical. How they do that seems to be not in the public domain, but there have been a few guesses (see http://www.dvxuser.com/V6/showthread.php?t=206797 and http://luminous-landscape.com/forum/index.php?showtopic=38713).
    One approach would be to simply read every second row of sensor pixels (1500 rows read from the original 3000) and once you have those in memory, delete every second column (2000 columns left). You would end up with a 2000 x 1500 image which could then be resampled to 1920 x 1080.
    I'd like to simulate what the camera appears to be doing, by generating a 4000 x 3000 test image and then asking Photoshop CS4 to delete the appropriate rows and columns. It may not necessarily be every second row; the Canon 5DMk11 appears to read every third row, so I may need to delete two out of every three rows.
    Can Photoshop do that sort of thing? If so, how?

    Thanks for the suggestions. Yes, I did take a detailed look at your images, but they weren't 100% convincing because it wasn't clear just what was happening. And Adobe's explanation, after reading it again, explains nothing at all to someone who doesn't know how Nearest Neighbor works.
    But you are correct -- Nearest Neighbor does effectively delete pixels. I proved it with the attached 6 x 6 image of coloured pixels (the tiny midget image right after this full stop -- you'll have to go to maximum zoom in PS to see it).
    These are the steps to delete every second row and then every second column.
    1. Select Image > Image Size.
    2. Set Pixel Dimensions > Height to half the original (in this case set to 3 pixels).
    3. Set Resample Image to Nearest Neighbor.
    4. Click OK and the image shoould now consist of three vertical white strips and three vertical Green-Red-Blue stripes.
    5. Repeat steps 1-4, but this time set Pixel Dimensions > Width to half the original (in this case set to 3 pixels). The image should now consist of three horizontal stripes Green-Red-Blue.
    Just to make sure the method worked for every third pixel, I repeated the above steps but with 2 pixels instead of 3 and obtained the correct White-Green, White-Green pattern.
    I resampled the Height and Width separately for the test so that I could see what was happening. In a real example, the height and width can be changed at the same time in the one step, achieving the same results as above.
    Finally, how to explain how Nearest Neighbor works in the simple cases described above?
    Division by 2
    In the case of an exact division by two (pixels numbered from top leftmost pixel), only the even numbered rows and columns remain. To put it a different way, every odd numbered row and column are deleted.
    Division by 3
    Only rows and columns 2, 5, 8, 11... remain.
    Division by N
    Only rows and columns 2, 2+N, 2+2N, 2+3N... remain.
    To put it simply, a resample using Nearest Neighbor (using an exact integer multiple) keeps every Nth row and column, starting from number two. The rest are deleted.

  • Lock rows and columns header in a table view report. It is possible?

    hi,
    I have a Dashboard that displays a report in "Table View" with many rows and columns.
    Is it possible to set a lock on the rows and columns like Excel?
    This would have blocked such headers that contain attributes and measures and to browse the report (eg with a scroll bar) had always viewed the headers.
    Can you help me?
    Thanks

    hi,
    please go through this discussion
    Re: SCROLL BAR to FREZZ HEADERS
    thanks,
    saichand.v

  • Is it possible to switch the rows and columns?

    Is it possible to switch the rows and columns of a table? The reason I ask is that it would be easier for me to input the data with the number at the top of a column and the fields going down. But it would be easier to read the data with the number on the left and the fields going to the right. Is it possible to switch a table in this way?

    mahongue wrote:
    Is it possible to switch the rows and columns of a table? The reason I ask is
    that it would be easier for me to input the data with the number at the top
    of a column and the fields going down. But it would be easier to read the
    data with the number on the left and the fields going to the right. Is it
    possible to switch a table in this way?
    It sounds to me as though you wish to transpose a table so that the original is changed from rows to columns and from columns to rows, as in the following:
    Table 1
        A   B   C
    ========
    1   o   p   q
    2   r   s   t
    3   u   v   w
    Table 2
        A   B   C
    ========
    1   o   r   u
    2   p   s   v
    3   q   t   w
    You are right - it would be nice to have a menu item to magically transpose a selected block of cells. But there isn't one. So...
    One way to solve this is to use the index() and transpose() functions to accomplish row and column cell transposition. If you are going to use a 1:1 cell correspondence and change the header columns and rows also, you can use this:
       =INDEX(TRANSPOSE(Table # :: <range>),ROW(),COLUMN())
    where Table # and <range> is substituted as in the following fashion:
       =INDEX(TRANSPOSE(Table 1 :: $A$1:$C$3),ROW(),COLUMN())
    Create a second table. Copy the modified formula above with the appropriate substitutions, select the range you wish to have your transposition inserted into (must match the transposed cell dimensions of the original range), paste the forumula and voila! the cells will be transposed.
    Cautions:
    o The target table must match the swapped cell length and width dimension. For example, if the original data range is 6 columns wide by 4 rows deep, then the corresponding table or range to hold the transposition must be 4 columns wide by 6 rows deep.
    o If your transposed data block is to be offset from the origin of the new table, then you will need to include a subtractive offset into your cell formula, since in the transpose() function the data in the master data range is referenced from its position with the master range, not its cell position in the table. Such an offset is necessary because this example formula uses the target row and column numbers to arrive at indexed positions.
    For example, if the new data range is to be offset one column to the right and one row below from the target table's origin then you must subtract (-1) from the cell and from the column references in the formula:
      Example:
      =INDEX(TRANSPOSE(Table 3 :: $B$2:$D$4),ROW()-1,COLUMN()-1)
    If someone has a better solution I'd be glad to hear of it.

  • How Calculate more than one value and store it into to different rows and column for each input?

    thx guys.....i have a progress now in LV
    But now i have new trouble here. Ok i attached my LV file (LV 7.0.1/7.1) and excel form. I just could'nt calculate more than one input value. I want a different result for each value that i enter ... and store it into different rows and column. But it just store at one row.
    Attachments:
    My Project.vi ‏31 KB
    rumus motor bakar.xls ‏14 KB

    duplicate post

  • Keeping row and column headers while scrolling inside a Web Dynpro table

    Hi,
    I have to display a 2x2 matrix with storage location names on the x-axis (i.e. as Column Headers) and material names on the y-axis (i.e. row headers). The table data represents the quantities of a particular material in a particular storage location.
    I am using dynamic UI generation to create this table. It can contain as many as 150 columns and almost as many rows. I dont want a page level scrollbar, and hence, have placed my table inside a scroll container UI element with a fixed height and width.
    I need a way to let the users use the scrollbars inside the scroll container, but still let them see the row  and column headers. Is there a way that I can do this in Dynpro for Java?
    Thanks,
    Navneet Nair.

    Hi Kenn,
    You are probably better off posting this request in this forum User Interface Development in ABAP as you are more likely to get a response.
    Cheers,
    Neil.

  • Make Select rows and columns as read only in Table Control

    Hi All,
    I would like to know how to make certain cells in a Table Control as display only.
    Table control should look like-(Those in bold are read only or in display mode)
    <b>Name1            Idno1 </b>         Address1
    <b>Name2            Idno2</b>          Address2
    <b>Name3            Idno3  </b>        Address3
    <b>Name4            Idno4</b>          Address4
    (Blank row to enter name idno and address)
    (Blank row to enter name idno and address)
    (Blank row to enter name idno and address)
    My table control should display all the above fields the way it is above of which first two colums and 4 rows should be read only,and the rest of the empty rows in the TC should be in change mode.i.e it must have provision to add new rows but not change the first two columns of existing rows.
    In short I am looking at solution to hide particular no of rows and columns and <b>not the entire column.</b>

    In the PBO of the table control loop. just write these statements
    NAME and IDNO considering the fields on the screen.
    and WA_TAB is the table work area being passed to the table control to display the rows.
    if not WA_TAB-NAME is initial and not WA_TAB-IDNO is initial.
    loop at screen.
    if screen-name = 'NAME' or
       screen-name = 'IDNO'.
    screen-input = <b>0</b>.
    modify screen.
    endif.
    endloop.
    endif.
    which means that the fields are disabled only if NAME and IDNO are not initial.
    Regards
    - Gopi

  • Hi, how can i break the value for a row and column once i have converted the image to the array?????​??

    Hi, I would like to know how can i break the value for a row and column once i have converted the image to the array. I wanted to make some modification on the element of the array at a certain position. how can i do that?
    At the moment (as per attachhment), the value of the new row and column will be inserted by the user. But now, I want to do some coding that will automatically insert the new value of the row and the column ( I will use the formula node for the programming). But the question now, I don't know how to split the row and the column. Is it the value of i in the 'for loop'? I've  tried to link the 'i' to the input of the 'replace subset array icon' , but i'm unable to do it as i got some error.
    Please help me!
    For your information, I'm using LABView 7.0.

    Hi,
    Thanks for your reply.Sorry for the confusion.
    I manage to change the array element by changing the row and column value. But, what i want is to allow the program to change the array element at a specified row and column value, where the new value is generated automatically by the program.
    Atatched is the diagram. I've detailed out the program . you may refer to the comments in the formula node. There are 2 arrays going into the loop. If a >3, then the program will switch to b, where if b =0, then the program will check on the value of the next element which is in the same row with b but in the next column. But if b =45, another set of checking will be done at a dufferent value of row and column.
    I hope that I have made the problem clear. Sorry if it is still confusing.
    Hope you can help me. Thank you!!!!
    Attachments:
    arrayrowncolumn2.JPG ‏64 KB

Maybe you are looking for