Group by calculation

select
802 as acct1, 803 as acct2,100 as amt1 ,-100 as amt2
into #Acct
Insert INTO #Acct
select 802,803,100,-100
UNION ALL
select 803,802,-100,100
UNION ALL
select 803,802,-100,100
UNION ALL
Select 803,802,-100,100
Hi,
I inserted the sample data as sql,
I have acct1 and acct2 with amounts, I need output like this
Acct1   Amount
802     500 (from both amount fields)
803     -500(from both amount fields)
i can do this by using self join , but this table has million records, please give me a better solution

if have mutiple column associated to the accounts and needs to calculate the same way
You can extend the same solution for multiple columns
ie like
SELECT amt,
SUM(field1) AS field1,
SUM(field2) AS field2,
SUM(field3) AS field3,
FROM Tablename t
CROSS APPLY (VALUES (amt1,field11,field21,field31,..),
(amt2,field12,field22,field32,..),
)tmp(amt,field1,field2,field3,..)
GROUP BY amt
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page

Similar Messages

  • Group By Calculated Columns Issue

    Dear All,
    I have some lists and libraries which has some calculated columns for calculating year and month based on created date and we have custom views which has group by on those calculated columns. The problem is group by is not working as expected. Attached are
    the screens for reference. We have also applied the June CU still no luck.
    Please help us on the resolution to the same.
    Rajani.J

    Make sure you dont have space in the data by any chance. You can try recreating the view again.
    Mark ANSWER if this reply resolves your query, If helpful then VOTE HELPFUL
    INSQLSERVER.COM
    Mohammad Nizamuddin

  • Group by calculated column?

    How can one group by a colum that is derived? E.g.
    select
    a.col1,
    a.col2,
    (select count(*) from table_b b where b.ix=a.ix) as foo,
    count(*)
    from
    table_a a
    group by ??????
    Unlike "order by" I cannot simply "group by 1,2,3", and calling out the volumn alias "foo" doesn't work either.

    SELECT   a.col1
    ,        a.col2
    ,        SUM(DECODE(b.ROWID,NULL,0,1)) foo
    ,        COUNT(*)
    FROM     table_a       a
    ,        table_b       b
    WHERE    a.ix = b.ix (+)
    GROUP BY a.col1
    ,        a.col2
    /

  • Group share calculation

    Hello,
    A owns B by 80%, B owns C by 70%, C owns A by 10% and B by 5%
    What is the algorithm the system uses to compute group share for B, C?
    Does it use multiple iterations and does it solve the system of equations for this?
    Is this algorithm documented somewhere? (exept for simple example in the hepl)
    Thanks

    Hi Alexey,
    No doucments on this available in SAP. However, you can test if system resolves such complication thru equation.
    Best Regards,
    UR

  • Grouping By a Calculated Column Issue

    Hi,
    I have 2 issues when I try to group by a view using a calculated column:
    It will show the number of items under each group but you expand is not showing any items at all
    It will show the item reproduced 333 times.
    The first one it happens to all the lists and libraries on SharePoint 2013. However the second issue happened only in a document library that holds the employee Documents. The view is grouped by Document type column and the Employee column ( which is the
    calculated column). It shows multiple versions of the same document as stated above.
    Any help is very much appreciated.
    Thanks

    Hi,
    According to your description, there is an issue when grouping by Calculated column.
    It was a known issue in the early build version of SharePoint 2013, it is already fixed in the August 2013 CU:
    http://blogs.technet.com/b/steve_chen/archive/2013/03/26/3561010.aspx
    I suggest you install August 2013 CU or the later versions and then create new list for a test.
    Best regards
    Patrick Liang
    TechNet Community Support

  • CRM 5.0 IPC Group Condition

    Friends,
    We have a requirement to implement a group condition in CRM IPC 5.0.  We have it implemented in R/3 and it works fine.  We have replicated the code in the IPC and it is being hit.  The code is quite simple.  We copy to subtotal 1 a the net line value if the condition ZDC1 exists on the line.  We then want the group basis calculation to only include the totalling of those lines that had ZDC1.
    As I mentioned, this works fine in R/3.  In CRM it is including the value of all the lines regardless of whether there is a ZDC1 condition or not.  The Java code is getting hit and doing the transfer of the value to subtotal 1 at the right time. 
    Is there something else we should be setting up in the custom fromula for a group condition?  I see in the IMG in CRM where I can add formula and implementation attributes.  Is this something I need to do to get the group condition to work correctly?
    Regards.
    KB

    We put code in to write the condition out to a log file to ensure that the correct values were being calculated.  Once we did this, the condition started working.  No clue why.

  • Schema group on vendor master ..?

    hi all
    Can anybody explain me about the schema group in MM
    1. what is schema group
    2.Its significance
    3.Where to configure//
    Thanks
    sap-mm

    Hi,
    Group for calculation schema (vendor): - Determines which calculation schema (pricing procedure) is to be used in purchasing documents containing this vendor number.
    Use: - You can use the schema group to specify the calculation schema per purchasing organization or vendor. The relevant calculation schema is determined by reference to the schema group.
    The effect of this is that the conditions to be maintained in a purchasing document can differ depending on the relevant purchasing organization or vendor.
    If a calculation schema is only to be valid for certain purchasing organizations or vendors, proceed as follows:
    1. Define the schema group for the purchasing organization or the vendor using the relevant function in the menu "Calculation schema -> Schema groups".
    2. Assign the schema group to the calculation schema via "Calculation schema -> Determine schema".
    3. Enter the schema group for the vendor in the vendor master records to which the calculation schema is to be assigned. Assign the schema group of the purchasing organization to the relevant purchasing organization using "Calculation schema -> Schema group -> Assign to purch. org.".
    You can  configure it in path SPRO > MM > Purchasing > Conditions > Define Price Determination Process > Define Schema Group, here do following;
    Schema Groups: Vendor
    Schema Groups for Purchasing Organizations
    Assignment of Schema Group to Purchasing Organization

  • Calculated items to be created on rows as well as on columns of a pivot tab

    Hello Experts,
    My Report has 3 columns . First is Hierarchy(parent-child) column, second is Fiscal Month and third a measure. I have multiple groups and calculated items added in selection pane for the Hierarchy column.
    I created a pivot table using above 3 columns where in rows bucket I have hierarchy column,in columns bucket I have Fiscal Month and in the measures bucket I have the measure.
    Now when I try to create a calculated item on Fiscal Month like $-1-$-2, I get the following error.
    Error Codes: OAMP2OPY:U5V5TIAH
    DXE expression interpreter error. Invalid "alias" attribute value. Source name: . XML: <sawxd:expr xmlns:sawxd="com.siebel.analytics.web/expressiondxe/v1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sawq="com.siebel.analytics.web/querydxe/v1.1" xsi:type="sawq:field" alias="s_2"/>
    To add, the report works fine when I remove the calculated items based on Hierarcial column.
    Please help to resolve this issue and identify the root cause.
    Thanks and regards.
    Edited by: 900085 on Sep 1, 2012 4:38 AM

    This is a bug with Oracle now. Find the details below.
    Bug 14580738 : ERROR : OAMP2OPY:U5V5TIAH WHEN ADD CALCULATED ITEM IN 2 SECTIONS AND USE $ SIGIN

  • GROUP CONDITION ROUTINE IN PO

    Hi all,
    in M/06 I have put flag GROUP CONDITION  and I have choosen GROUP CONDITION ROUTINE 3 (material Pricing group).
    Calculation Type= Quantity
    Scale basis= Quantity
    I have created 2 condition records for 2 materials with scales.
    These 2 materials have the same material price group.
    Why when I do purchase order the system doesn't accumulate the item quantities?
    If I do the same configuration in SD the system sum the quantities and get the right scales for each material.
    Does the  group condition routine 3 valid only for SD documents (Sales Order) and not for MM documents (Purchase Order)?
    Thanks a lot
    Best regards
    Alba Battolini
    Moderator message: Thread locked because of violating forum rules: subject in capital letters. Please read and  follow the forum rules
    Edited by: Jürgen L. on Mar 9, 2012 4:38 PM

    HI,
    Condition type for Planned delivery cost, like FRA1, FRB1,ect, have Acc. key& Accrual key like FRE, FR1 in PO pricing procedure(calculation schema)
    Deselected the indictor of Statistics.
    By doing it will included the deliverycost into the net price by removing Statictis indicator.
    Regards
    KK

  • Using Cannibalization Group with just DP implemented

    Hi
    I have just implemented Demand Planning (DP) and won´t implement other APO module.
    I want to use the cannibalization group (transaction /SAPAPO/MP32), but I have to click the BOM button (shift+F6) to bring and see the products. I don´t need the BOM for DP.
    Can´t I use the Cannibalization group if I just implement DP or what should I do?
    Thanks in advance

    Hi LCD777,
    If you use cannibalization, the products that you want to plan in Demand Plnning must be
    defined as products in the APO master data.
    To use cannibilization groups, you must include a characteristic for the product in the
    planning book. If you do not use 9AMATNR for the product, you must specify which
    characteristic is the product in the master planning object structure.
    You specify the cannibalization group when you create a promotion for a product. The
    promotions for the other products in the cannibalization group are calculated automatically.
    Regards
    R. Senthil Mareeswaran.

  • Age group to make it time dependent display as per transaction date

    Hi All,
    I have a doubt in displaying a attribute as time dependent. Below is my scenario.
    I have a cube where am capturing the transaction data of the customer. Currently while the customer data loading using the customer number i do look up to the customer master data and findout the D.O.B and calculate the Age group(bucket) and punch it in the transactin cube itself. Note Age group is calculated based on the DOB and the transaction date. It was working fine.
    But issue raised today customer is registered and he is allowed to do some transactions immediately after that, and the personal details like DOB, address is captured latter. Hence all the transactions until his DOB is maintained in the source system is puched in cube w/o DOB.
    Hence i do not want to have it in the cube and want to have the age group to be fetched from attribute / some other mean. But in case if i make the agegroup as attribute of the customer it will show only the current age. But i need to show the agegroup as on the transactions date.
    For ex. today customer age is 25 and day after tmr his age changes to 26. And in this case if i execute the report for whole month under 25 i should get the transaction and under 26 age i should get the respective transaction.
    how should u achieve this. please help me out.
    Note: Having a virtual KF seems createing the performance issue because data volume pulling out is more in numbers.
    thanks in advance
    Prem

    Hi,
    In this scenario i think Virtual Key figure is inevitable.
    Hope that helps.
    Regards
    Mr Kapadia
    *Assigning points is the way to say thanks.**

  • Performance factors for criteria based groups

    I am trying to understand what factors impact the performance of a criteria based group. I have read that member size has direct impact, but it does not make much sense, When a resource is updated, FIM looks for all criteria based groups that have criteria
    containing the attributes updated in the resource and recalculates the membership of those groups. So my understanding is that the performance of criteria based group is dependent on the criteria, not on the member size of the group. If you have a lot
    of criteria, then FIM will spend more time on evaluating the criteria and the chance of matching the attribute with the attributes updated in a resource will increase. The member size should not have much impact here.
    Yes, member size can be an issue, but that will not be limited to a criteria based group - that should apply to any groups with large number of members. Because that impacts the memory footprints and complexity of membership calculation both in Sync
    and in AD.
    Is my understanding correct, or I am missing something?

    If you have a lot of criteria, then FIM will spend more time on evaluating the criteria and the chance of matching the attribute with the attributes updated in a resource will increase.
    For this, I know that in FIM 2010 R2 a new optimization feature came which fetches the information of "Common Criteria" from maximum number of groups and sets and uses this feature for calculating the group membership in a much faster
    way which enhances the performance.
    You can also, use the Deferred option in groups for calculating group membership. It is also a feature of FIM 2010 R2 for better performance.
    http://technet.microsoft.com/en-us/library/jj863243(v=ws.10).aspx
    Regards,
    Manuj Khurana

  • Dynamic Height in Graphs does not work properly when the graph is in an list

    Help please,
    I have an report in SQL Server 2008 (SP1) Reporting Services which uses Dynamic Height to dynamically increase the size of the graph for the data. For a single dataset this works great!
    When I place this graph in a list/tablix (to display this graph on each group) things go bad... Only the first graph on every page is resized, all other graphs on the same page are equal in size of the first!
    When I place a pagebreak on the lists property all graphs are drawn fine!! But then I will have a page for every question in my data (which can be a lot!)
    What is going on here? Please help.

    Hi Jerry,
    thanks for your reply, but this does not work. The graphs are now all the same size (the size of the first one that is), and on the same page for that matter...
    It looks like the renderer calculates the value of the dynamic height only once on a page in stead of each graph. That's a bug in my opinion.
    Any suggestions on how to fix this?
    The inner workings of the report are like this: The data contains anwers from a survey by question, so i have a unknown count of answers with each question; I placed a list on my report with a groupingproperty on the question asked. On this list i place a horizontal bar-graph which must grow in height when it is too small. The dynamic height should be calculated like this =70 + (CountDistinct(AnswerValue.Value)*10) & "pt".
    When i place this calculation in a textbox, every item in the group is calculated correctly. Each graph is drawn, but the graphs are sized only to the size of the first graph on the page. When I place a pagebreak after each list-repeat (so i get each question on a seperate page) each graph is drawn correctly! This results however in more than 100 pages with all used for just a few centimeters (think about trees!).
    I'm using SQL 2008 / SSRS2008 with SP1 by the way ( without SP1, the behaviour is the same).
    Any more suggestions are appreciated.
    Danny

  • How do I create a URL to filter a view when the value I have from list one is the ID that was used by list 2 to pull in the list 1 title?

    My list "Tasks" has an record with Title = "Build SSIS for Duke Energy" and its ID is 1. Then I have a list "Journal" where I have tracked entries related to the progress of the task. When I create the Journal entries I passed
    in the ID of the task 1 which then pulled the title into the Journal's Associated task lookup column. Now I'd like to have a column in the Tasks list that would have a URL to take me to all journal entries related to the Task. But passing in the ID 1 of the
    task does not work. 
    If the lookup column has the actual Title from the task in all the time and it is not dynamically pulled every time the list is queried shouldn't I be able to filter on the Title e.g. "Build
    SSIS for Duke Energy"  

    I ended up going with a workflow to build the URL and sending the title to the look-up column. 
    I tried the script at that site and ran into several problems. It didn't work with views that were grouped, the calculated links did not show on the edit and view forms. I assume those forms would have to be changed to run the script also.
    In addition to, I have to add a CEWP to each view and I was also losing the "Items" and "List" options (next to "Browse") from the ribbon until I clicked around in the list. 
    What are the downfalls of a workflow? I ask because many people default to using a similar TextToHTML script like you mentioned.

  • Row subtraction in obiee 11g

    Hi ,
    I want to display my report as given below. I have achieved till displaying the values using pivot table in obiee 11g
    India
    Product     amount
    a     50
    b     35
    America
    Product     amount
    a     100
    b     50
    Can someone help me to achieve the below substraction of rows in obiee 11g ?
    India
    Product     amount
    a     50
    b     35
    a-b     15
    America
    Product     amount
    a     100
    b     50
    a-b     50
    Thanks,
    Pavni

    Hi...
    Follow the steps:
    1)Create a Pivot view
    India
    Product amount
    a 50
    b 35
    America
    Product amount
    a 100
    b 50
    2) Click on selection steps:
    Under the product column click on Then, New Step... ->      Add Groups or Calculated Items -> New Calculated Item
    or (else u can select this option New Calculated Item from result pane besides New View)
    Display Label Name: a-b
    Values From: Product
    Function: Custom
    Here u should select and write condition like
    Product a - Product b
    Click ok, then save....
    See the result......
    Mark as a correct it helps u....
    Thanks

Maybe you are looking for

  • How to set up one-button embed-hotlinking for Flash SWF?

    Hello, I'm publishing a webcomic in Flash.swf format and I'd like to make it as easy as possible for people to grab my comic and put it on their website. How can I set up one-button hot-linking that will automagically provide the code so that they ca

  • How to create Telnet CLI in JAVA

    Hi Guys, I work on a JAVA project that has two parts. In one part we provide Command Line Integration(CLI) for users. Now the CLI part exist in C++ .So, we use JNI to connect it to my java project for processing it. Now I am thinking of converting my

  • Accessing excel documents fom KM

    Hi all I have a problem accessing excel documents in Hebrew from the KM. If the document's name length is more then 23 characters (in Hebrew),I get a "This page cannot be displayed" error. It happens only if I work with Excel 2002 (XP) version. Excel

  • File Sharing between OS X 10.4.8 and OS 9.2.2

    I have seen a couple of postings on this topic and have tried to do what is suggested without success. I'm setting up a new Mac Pro and need to pull files from an ancient G4. I have the G4 set up for network sharing. I have set up a network called "H

  • What does it mean when you get the notification certificate for this server is invalid

    What does the following mean -the certificate for this server is invalid?