Divide a column by the Sum of the Column

Hi!
I have a challenge in dividing a column by the total of that same column. What I wan to archive is first check if a column is zero before dividing by the total of the column  and then multiply by 100 to get the percentage of total contribution.
Below is a sample image. I equally will want to round up to 2 decimal places. As it below, the percentage contribution column is derived from the CountOfProduct column
Thanks so much for the help
Zionlite

Use the SUM() OVER() window function, e.g.:
DECLARE @tablename TABLE
product VARCHAR(30) ,
category INT ,
prodcnt INT
INSERT INTO @tablename
VALUES ( 'PROD1', 1, 11 ),
( 'PROD2', 1, 10 ),
( 'PROD3', 2, 13 ),
( 'PROD4', 2, 40 ),
( 'PROD5', 3, 1 );
SELECT O.product ,
O.category ,
O.prodcnt ,
1.0 * O.prodcnt / ( SELECT SUM(I.prodcnt)
FROM @tablename I
FROM @tablename O;
SELECT O.product ,
O.category ,
O.prodcnt ,
1.0 * O.prodcnt / SUM(O.prodcnt) OVER ( )
FROM @tablename O;
SELECT O.product ,
O.category ,
O.prodcnt ,
1.0 * O.prodcnt / ( SELECT SUM(I.prodcnt)
FROM @tablename I
WHERE O.category = I.category
FROM @tablename O;
SELECT O.product ,
O.category ,
O.prodcnt ,
1.0 * O.prodcnt / SUM(O.prodcnt) OVER ( PARTITION BY O.category )
FROM @tablename O;
Data by
Prashanth.
Caveat: For further processing avoid to formatting of the fraction to percent. Do this in the front-end.

Similar Messages

  • How to get the sum in appropriate column without a red triangle appearing?

    Hello,
    In 'Numbers" - How do get columns to add (calculate) the sum in each decending column on an Expense Report.
    When I highlight the decending column the total appears on the far left of the screen.  When I drag the sum amount from there to the appropriate column a red triangle with an ! appears instead of the amount.
    Thanks for your immediate help.

    The red triangle is an Error triangle. Clicking it will display the error message and tell you what error has occurred. From your description, my assumption is that you dragged the SUM() function from the quick calculations at the lower left and dropped it intto a cell in the column being summed.
    If that's the case, this is likely the error message you would see:
    When you highlighted the 'decending column,' you likely selected all of the cells in that column, including the one into which you dropped the function.
    Instead, do one of the following. These assume the column you want to sum is column B.
    If you want the sum at the top of the column:
    Make sure the row you want the sum to appear in is a Header row.
    Enter this formula into any Header Row cell in column B:   =SUM(B)
    If you want the sum at the bottom of the column:
    Add a Footer row to the table. (Go Table (menu) > Footer Rows > 1).
    Enter this formula into the Footer Row cell in column B:   =SUM(B)
    SUM (and other functions) that expect a range of cells will interpret a cell reference entered using only the column letter (B) as meaning 'all of the non-header, non-footer cells in column B', and will exclude those cells in header or footer rows.
    Regards,
    Barry

  • How to find the sum of a column

    I need to find the sum of a column and use it in a different column. The following is the example.
    Column names: Feedback(Good, Avg, Poor), Count(no of good, no of avg, no of poor) and %age(Feedback/sum(feedback))
    I want to find the sum in Java class and also calculate the last column in java class.
    Please tell me some way to do it.

    oh.. ok ..thanks for letting me know.. i will formulate the question in a proper way:
    This is what my UI should look like:
    Rating Count Percent
    Excellent 2 20
    Good 6 60
    Poor 1 10
    Bad 1 10
    Now i have the following columns in the data base:
    Meaning and feedback_rating.
    So the following SQL Query:
    SELECT hrl.meaning rating,
    sum(decode(bcpi.feedback_rating, null, 0, 1)) counted
    from cmp_cwb_person_info bcpi ,
    hr_lookups hrl
    group by hrl.meaning
    will give me the result as
    rating counted
    Excellent 2
    Good 6
    Poor 1
    Bad 1
    Now I want a third column as percentage : Earlier we were doing this calculation in the sql query itself, so the query was like
    SELECT hrl.meaning rating,
    sum(decode(bcpi.feedback_rating, null, 0, 1)) counted,
    sum(decode(bcpi.feedback_rating, null, 0, 1))/(max (select count (*) from cmp_cwb_person_info bcpi ,
    hr_lookups hrl )) percent
    from cmp_cwb_person_info bcpi ,
    hr_lookups hrl
    group by hrl.meaning
    Hence the third column (percent) was calculated in the sql query itself.
    But now i feel that the performance of the query could be improved if we get the first two columns from the database and the calculate the third column programatically in the java code.
    So this is what I want to know. How can i do that?

  • How do you get the sum of two columns multipied together?

    I can't seem to figure out how to get the sum of two columns multiplied together without having to manually type out each location (example: A1*B1+A2*B2+A3*B3, etc..).  Though the idea seems to be rather simple, everything I have tried has only given me an error.  I know there must be an easier way of doing this, but I get lost in the explanations given in 'help' area of numbers, can someone help me?

    C3=SUMPRODUCT(A3:A18, B3:B18)
    the function SUMPRODUCT() takes ranges and multiplies corresponding cells in the ranges, then adds them together.
    I the case I show SUMPRODUCT() performs:
    A3*B3 + A4*B4 + A5*B5 + A6*B6 + ... +  A18*B18
    If you want to perform the same operation on the whole column (s) you could modify the formula:
    C3=SUMPRODUCT(A, B)

  • How to use trigger to catch the sum of a column is greater than 1

    Here is my problem.
    I create a table, which is preference( name char, percentage real);
    the sum of the percentage for some user(name) should be 1;
    And one user can have many records in the table as needed.
    I should to validate the insert data which is valid after a series of insert operation? How can I do it?

    Exactly what I was thinking:
    SQL> create table preference
      2  (
      3  name varchar2(20),
      4  percentage number(3)
      5  );
    Table created
    SQL> create materialized view preference_mv
      2  refresh on commit
      3  as select name,sum(percentage) total_percentage
      4  from preference
      5  group by name;
    Materialized view created
    SQL> alter table preference_mv add constraint c_pref_pct check (total_percentage = 100);
    Table altered
    SQL> insert into preference values ('name1',25);
    1 row inserted
    SQL> insert into preference values ('name1',50);
    1 row inserted
    SQL> insert into preference values ('name1',25);
    1 row inserted
    SQL> commit;
    Commit complete
    SQL> insert into preference values ('name2',10);
    1 row inserted
    SQL> insert into preference values ('name2',30);
    1 row inserted
    SQL> commit;
    commit
    ORA-12008: error in materialized view refresh path
    ORA-02290: check constraint (SCOTT.C_PREF_PCT) violatedSQL>

  • Total Baseline Hours For A Resource Does Not Equal the Sum of the Weekly Baseline Hours for that Resource

    Hi,
    I am using Project Server 2010. I have a project schedule that has been baselined and no actual work has been charged to it. The project has 3 resources. I am in the Resource Usage View. With 2 of the three resources, the hours in the Baseline Work Column
    on the left side of the view do not equal the sum total of weekly hours in the Timephased Grid. For instance, for resource JB the Baseline Work hours column says 1,392. When I total his weekly hours in the timephased grid I get 1368 hours; a variance
    of 24. Resource RS has 794.5 hours in the Baseline Work column but the sum total of his weekly timephased grid hours is 710.5, a variance of 84 hours. In both cases, the sum of the hours in the timephased grid is less than the hours in the Baseline Work column.
    What would be causing this? (I am cutting and pasting the weekly hours in the timephased grid into Excel and using the Excel sum function total).  Is there a better timephased view I should be looking at to try to find the "missing
    hours"? I have seen this before in project and it really has me stumped. Thanks.
    Judy Washington

    Hi Judy,
    I could not reproduce your issue. Is your Project Server patched with the latest SP and CU?
    Also can you reproduce this unexpected behavior with another project?
    Can you split your screen from the resource usage view, display the resource form and click right on the grey part selecting "schedule"? Then you'll have the scheduled start and finish dates for the resource's assignments. This is to be sure that
    you are not missing any parts of the assignments due to a wrong zoom in the timephased grid.
    Hope this helps,
    Guillaume Rouyre, MBA, MCP, MCTS |

  • The sum of the confirmed quantity exceeds the sum of stock items

    Hi,
    I have two sales order. Material is same. Both of them related project stok.
    First sales order's qty=1. I created purchase order and post goods receipt.
    Second sales order's qty=2. I created only purchase order.
    I cannot create delivery for first sales order. System giving message.
    Information message : The sum of the confirmed quantity exceeds the sum
    of stock items
    20000978     10     Only 0 ST of material 7ML18301CF  available
    20000978     10     An item with no delivery quantity is not permitted. Item will be deleted.
    But I have a 1 qty on project stock.
    Please help me.

    hi,
    this is to inform you that,
    please run this report in SE38, SDRQCR21 if you have any inconsistencies in the system.
    it seems there is an issue with MARD-DISKZ  & please correct it.
    but i have a doubt MB51 is material document llist.  why you are checking stock there.
    please confirm.
    regards,
    baljia
    Edited by: balaji timmampalli achari on Nov 17, 2010 9:00 AM

  • The cumulative balance displayed in FS10N does not match the sum of the det

    Hello,
    The cumulative balance displayed in FS10N does not match the sum of the details.  For example, we have a GL disbursement account that has a ***. Balance of 8 million.  The debit is 2 million and the credit is 10 million. But, when you drill down on the ***. Bal. for the current period, the sum of the details is 9 million.  According to our users, the 2 balances should equal.  I did a search in this forum and found 1 post stating they had the same issue and the answer was to run f.16. Has anyone experienced this and if so, how did you handle it?  I'm not sure how f.16 functions.  Do we have to run it for each consecutive year?  I'm not a FI specialist.  I'm responsible for data archiving and the users think it's related to archiving.  However, we have a test system that was resynced with production prior to when archiving was done and it shows that this issue is pre-existing.
    Thank you very much in advance,
    Lourdes

    Hello,
    There is a possibility that you have activate line item display for some of the accounts at a later stage. Meaning that earlier postings were not be shown for the earlier postings but only totals will be made available. Therefore, obviously there is bound to be difference between line item report and totals report.
    You need to identify which accounts are being changed with line item display at a later stage.
    In case if you forget to keep GL Line item display for an account, but the posting are already made the following steps you would required to get the line item display retrospectively.
    1. Note that you are NOT required to make the balance of that GL account to ZERO. Please do not confuse with Open Item Management.
    2. Put the check box line item display for the account in FS00. Make sure you are entering right company code.
    3. Block the account for posting in COA Segment and Company Code Segment in FS00
    4. Go to SA38 and run program RFSEPA01 (Give correct GL Account and Company Code)
    5. Now, remove the block you kept on the GL Account in FS00.
    This will reset the line item display retrospectively.
    Hope this will solve your problem.
    Regards,
    Ravi

  • Display the Sum in the break header

    Is it possible to display the Sum in the break header instead of the breaker footer? Thanks.

    You can put a sum calculation anywhere you want. Insert a cell, and copy (or move) the existing sum formula into your newly created cell(s). If you stay within the block (table) then the numbers will stay the same. If you move outside the block (into a stand-alone cell, for example) then you may have to set the context of the calculation.
    Note that a running total may return different results than a standard total, which makes sense.

  • How do you get the percentage of one number compared to the sum of the total in an array in ipad numbers

    How do you get the percentage of one number compared to the sum of the total in an array in ipad numbers

    On the iPad my example looks like this:
    To fill the formula down you tap cell and then Fill:
    And drag the bottom part of the yellow rectangle down:
    Wayne's example would look similar.
    SG

  • My hard drive is clogging up automatically. The personal folder is now 921 GB which is much larger than the sum of the subfolders. I cannot see what's causing this or prevent this from happening. Anyone?

    My hard drive on my Imac keeps clogging up automatically. The personal folder is now 925 GB which is much larger than the sum of the underlying subfolders. I cannot see what"s causing this. Anyone?

    You may try one of these utilities to spotlight exactly where the hard drive usage has gone crazy.
          DaisyDisk- http://itunes.apple.com/us/app/daisydisk/id411643860?mt=12
         DiskFalcon   - http://itunes.apple.com/us/app/disk-falcon/id421781596?mt=12
    Items to check manually:
         Duplicate iTune libraries, or music files that are in itune folder AND loose on the harddrive
         Download folder that hasn't been emptied
         Backup software location

  • Getting the sum of the elements in an array

    Hello all,
    Any ideas on how to easily get the sum of the elements of an array of floating points (or any data type for that matter ) this is to be part of a method.
    arrayName (float [] floaters)
    Thanks

    int total=0;
    for(int a=0; a<array.length; a++){
      total=total+array[a];
    }now is that so hard?
    or even as a method
    public int addUp(int[] array){
       int total=0;
       for(int a=0; a<array.length; a++){
          total=total+array[a];
       return total;
    }to be used as
    int total=addUp(array);just write your own!

  • Get every 10 sec a int.value and need to take the sum of the last 18 values

    Hi,
    i get every 10 sec a int.value and need to take the sum of the last 18 values (3 minutes).
    the programm should work permanently.
    I tried with a 1d-array but didn´t get a result. Could anyone help me?
    Best regards
    kasche

    Use the example in the posted link, then add another shift register for your sum of all elements. Dont add all the elements every time, add them to a running total when they come in. You will need to evaluate how big this number is going to get, however, and decide if you should use an I64 for your running total of all elements. Even this will overflow eventually. 
    So your code would look like that posted by GerdW in the above link, then add a shift register with a starting value of 0. Then add your input value to the value comming from this shift register and send the output to the shift register's output terminal. This creates your running total of all values. The code by GerdW provides your "last 18 elements" total in a very efficient manner, just change the 15 to an 18.
    I have attached a sample bit of code to make it clear. I saved it in LV 8.0 so more people can open it.
    CyberTazer
    Software Systems Engineer
    Attachments:
    Running 18 total.vi ‏11 KB

  • How to count number of rows as well as the sum of a column in a procedure

    Hi, i need to count the number of rows a sql returns in a procedure.
    as well as i need to sum up a different column.
    i need the following output:
    count the number of rows output
    and sum the total column
    code:
    procedure samba_extraction (p_errmsg IN out varchar2
    ,p_errcode IN out NUMBER
    ,p_filename in varchar2
    ,p_start_date varchar2
    ,p_end_date varchar2)
    is
    file_handle utl_file.file_type; -- file handle of os flat file
    -- cursor to select the c_samba_resources
    cursor c_samba is
    select
    lpad(h.contract_number,15,'0') contract_number
    ,h.short_description description
    ,h.attribute_category context_value
    ,h.attribute7 samba
    ,h.attribute8 samba_number
    ,h.start_date start_date
    ,h.end_date end_date
    ,h.sts_code active_inactive
    ,l.price_negotiated price
    ,l.tax_amount tax
    ,LTRIM(to_char((l.price_negotiated + l.tax_amount),'00000000.00')) total
    from
    oks_auth_headers_v h
    ,oks_auth_lines_v l
    where h.id = l.chr_id
    and ((h.start_date <= (p_end_date))
    and (h.end_date >= (p_start_date)))
    and h.attribute7 = 'SAMBA'
    -- and h.sts_code = 'ACTIVE'
    and ((h.attribute_category = 'SUBSCRIPTION.DURATION')
    or (h.attribute_category = 'SUBSCRIPTION.VALUE')
    or (h.attribute_category ='SUBSCRIPTION.QUANTITY'));
    l_output varchar2(1000);
    l_counter varchar2(11);
    l_total varchar2(11);
    l_filename varchar2(30);
    begin
    if p_filename IS NOT NULL then
    -- l_batch_no := 'T';
    l_filename := p_filename || '.txt';
    -- open file to write into and obtain its file_handle.
    file_handle := utl_file.fopen('/usr/tmp',l_filename,'W');
    fnd_file.put_line(fnd_file.log,'The '|| l_filename||' file you have requested has been placed in the usr/tmp directory');
    for l_info in c_samba
    loop
    -- l_output := null;
    l_output := l_info.samba_number||'+'||l_info.total||l_info.contract_number;
    utl_file.put_line(file_handle,l_output);
    fnd_file.put_line(fnd_file.output, l_output);
    dbms_output.put_line(l_output);
    end loop;
    else
    p_errmsg := ('Please enter a filename for this file ');
    write_log('UPDATE : ' ||p_errmsg);
    end if;
    -- close the file.
    utl_file.fclose(file_handle);
    exception
    when no_data_found then
    dbms_output.put_line('no_data_found');
    utl_file.fclose(file_handle);
    when utl_file.invalid_path then
    dbms_output.put_line('UTL_FILE.INVALID_PATH');
    utl_file.fclose(file_handle);
    when utl_file.read_error then
    dbms_output.put_line(' UTL_FILE.READ_ERROR');
    utl_file.fclose(file_handle);
    when utl_file.write_error then
    dbms_output.put_line('UTL_FILE.WRITE_ERROR');
    utl_file.fclose(file_handle);
    when others then
    dbms_output.put_line('other stuff');
    utl_file.fclose(file_handle);
    end samba_extraction;
    end xx_samba;

    Hi,
    Initialise one variable TOT_ROWS to 0.
    Then in the for loop
    tot_rows := tot_rows + +1 ;
    so after for loop the value in the tot_rows will be the total records..
    If u want it to get this value in the calling procedure of this , just declare tot_rows parameter as out parameter.
    For sum of a column:
    Initialise a variable sum_col to 0.
    In the for loop
    sum_col := sum_col+I_info.column_name
    aprameter if u wish return this value as out..
    I think this wil give u the o/p..
    cheers,
    Sivarama

  • How to get the sum of  a column in a table layout region

    i have page table layout region and i have many rows in that ...i have a column say xyz now i want the sum of all xyz in all rows ...is that possible ..if it is how..????
    please help me out in this issues...so that i can proceed further with my work..im stuck otu here....if the solution r there in the devguide please tell me where it is ..i mean under which section...bcoz it 1400page document...

    If you are mentioning about table/advanced table region you can enable totalling in those regions. Please check the Table / Advanced Table section as appropriate in Chapter 4 of the dev guide.
    If it is not a table / advancedTable then you will have to programmatically total the column value and display it in the appropriate cell.

Maybe you are looking for

  • Group Policy Infrastructure Failed : The target name is incorrect

    Hi, I am currently facing issues regarding Group Policy, users are unable to change the password. When i run gpupdate /force on servers, the user policy and computer policy are successful but when i run the same on any client i receive error as per b

  • Negative analog trigger voltage

    Hello, I am currently working on a program in Labview 6.1 with two E-series devices acquiring data simultaneously.  I am currently using a analog channel to trigger the acquisition.  My application uses a signal that has both positive and negative vo

  • Remove tenuous links to previous iMac owner

    Hi All OK, after various 'suggestions' from apple support personnel, I'm hoping someone here may be able to help. I purchased a second-user mid 2011 27" iMac with Mountain Lion. Using migration assistant, installed my TM backup from older Macbook Pro

  • Address Book in French?!

    My address book is in French, which is a problem since...I don't know any french... I check the system pref>international settings: all on english, no french involved. None of my other programs are operating in a different language. I tried going to

  • Bea WebLogic Server 8.1SP2 crashes

    Hey, we have a problem with the new release of WebLogic Server 8.1 SP2. For a while everything is going fine but after a few hours the server is too busy to process the requests. During the analyzing of weblogic parameters we found in the monitoring