Operators in using OWB-SUM and Condition

I have to write a condition like the following.
Please let me know how to do this
CASE WHEN COST = 'F' THEN SUM(I.LINE) ELSE 0 END TOTAL,
CASE WHEN COST = 'F' THEN SUM(I.ADJUSTMENT) ELSE 0 END ADJUST,
CASE WHEN COST = 'E' THEN SUM(I.ORIGINAL) ELSE 0 END ORI,
CASE WHEN COST = 'E' THEN SUM(I.ADJUSTMENT) ELSE 0 END ADJ_ORI

Hi
First define an expression operator with 4 Lines like this :
Line 1 named TOTAL :
CASE WHEN COST = 'F' THEN I.LINE ELSE 0 END,
Line 2 named ADJUST :
CASE WHEN COST = 'F' THEN I.ADJUSTMENT ELSE 0 END,
Line 3 named ORI :
CASE WHEN COST = 'E' THEN I.ORIGINAL ELSE 0 END ORI,
Line 4 named AGJ_ORI :
CASE WHEN COST = 'E' THEN I.ADJUSTMENT ELSE 0 END
Then, send these lines to an aggregate operator.

Similar Messages

  • Use of SUM and COUNT with GROUP BY

    All,
    I have a set like below:
    State DOB StartDt EndDt Desc Category MemberID SubID Code
    NC 2003-01-30 2014-01-01 2014-01-31 Child B 123456 2 38
    NC 2003-01-30 2014-01-01 2014-01-31 Child B 123456 2 39
    NC 2003-01-30 2014-02-01 2014-05-31 Child B 123456 2 38
    NC 2003-01-30 2014-02-01 2014-05-31 Child B 123456 2 39
    NC 2003-01-30 2014-06-01 2014-07-31 Child B 123456 2 38
    NC 2003-01-30 2014-06-01 2014-07-31 Child B 123456 2 39
    NC 2014-01-17 2014-01-01 2014-07-31 Infant S 456789 1 49
    NC 2014-02-04 2014-02-01 2014-07-31 Infant S 246376 3 49
    -- MemberID and SubID identify 1 member
    -- Member 123456 has 2 distinct "Code" i.e. 38,39 but each code has different "StartDt" and "EndDt"
    -- Expected Result
    State Desc Category CountOfDistinctCode TotalMonthsEnrolled
    NC Child B 2 (38 and 39 for same member) 7 months (1 + 4 + 2) (Difference between StartDt and EndDt:1 (1/31/2014 - 1/1/2014) + 4 (5/31/2014 - 2/1/2014).. )
    NC Infant S 2 (Same code 49 but different member) 13 months (7+6) (7/31/2014 - 1/1/2014 = 7 months + 7/31/2014 - 2/1/2014 = 6 months)
    I tried doing a count of distinct Code and the summing up the member months, grouped by State, Desc, Category, but I am not able to get 2 and 7 for child, it somehow calculates Months as 14 (7+7). Please let me know what you guys suggest.

    OK, so we need a different approach. We need a table of numbers, a concept that I discuss here:
    http://www.sommarskog.se/arrays-in-sql-2005.html#numbersasconcept
    (Only read down to the next header.)
    We join the numbers to temp table with BETWEEN over the numbers. Then we count the distinct combination of member ID and number.
    We also need to make an adjustment how to build the string for the DISTINCT. I initially assumed that your columns were integer, why I used str() which produces a right-adjusted fixed-length string of 10 characters. (The default, you can specify a different
    width as the second parameter.) But str() expects a float value as input, and will fail if for instance member id would be non-numeric. We cannot just concatenate the strings, since in that case (MemberID, SubID) = ('12345', '61') would be
    the same as ('123456', '1'). So we must convert to char to get fixed length. All that said, and some more test data added, here is a solution:
    CREATE TABLE #Test
    [State] CHAR(2),
    DOB DATE,
    StartDt DATE,
    EndDt DATE,
    [Desc] VARCHAR(8),
    Category CHAR(1),
    MemberID VARCHAR(10),
    SubID VARCHAR(2),
    Code VARCHAR(5)
    INSERT INTO #Test
    VALUES
    ('NC', '20130130', '20140101', '20140120', 'Child', 'B', '123456', '2', '38'),
    ('NC', '20130130', '20140121', '20140131', 'Child', 'B', '123456', '2', '39'),
    ('NC', '20130130', '20140201', '20140531', 'Child', 'B', '123456', '2', '38'),
    ('NC', '20130130', '20140401', '20140613', 'Child', 'B', '123456', '2', '39'),
    ('NC', '20130130', '20140601', '20140731', 'Child', 'B', '123456', '2', '38'),
    ('NC', '20130130', '20140614', '20140731', 'Child', 'B', '123456', '2', '39'),
    ('NC', '20130129', '20140601', '20140731', 'Child', 'B', '9123456', '1', '38'),
    ('NC', '20130129', '20140614', '20140831', 'Child', 'B', '9123456', '1', '39'),
    ('NC', '20140117', '20140101', '20140731', 'Infant', 'S', '456789', '1', '49'),
    ('NC', '20140204', '20140201', '20140731', 'Infant', 'S', '246376', '3', '49')
    SELECT * FROM #Test ORDER BY MemberID, StartDt, EndDt
    SELECT
    [State]
    , [Desc]
    , Category
    , COUNT(DISTINCT convert(char(10), MemberID) +
    convert(char(2), SubID) +
    convert(char(5), Code)) AS TotalCnt
    , COUNT(DISTINCT convert(char(10), MemberID) +
    convert(char(2), SubID) +
    str(N.Number)) AS CalMonths
    FROM #Test t
    JOIN Numbers N ON N.Number BETWEEN
    datediff(MONTH, '19000101', t.StartDt) AND
    datediff(MONTH, '19000101', t.EndDt)
    GROUP BY [State], [Desc], Category
    go
    DROP TABLE #Test
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Formula variable used in exception and condition - gives a check error

    The same formula variable is used in a condition and exception within a query. When I click on "check", I get the message "Variable <myvar> Is Used By More Than One Infoobject". The variable is a formula variable, processed by User Entry/Default Value, with optional entry, ready for input, Dimension "number", default value -0.01.  However, the query still saves, generates and executes without problem.
    This is with BW 7.0, SP 14.  And with query designer 3.5, version 3500.7.572
    I'd be grateful if a few people could try to reproduce this, letting me know their version.  To reproduce it:
    Create a query. Create formula variable processed by User Entry/Default Value, with optional entry, ready for input, Dimension "number", default value -0.01. Create a condition using the  variable. Create an exception using the variable. Click on Check. Save and execute the query.
    Thanks
    Matt

    It is a warning and you can ignore it , if in query execution you get correct result / output...(then it implies u r on safe side)
    But if you are so much concerned about warning then as a workaround just create another Formulae variable and use it in Condition and use the previous formulae variable for Exception.
    This way you will have 2 variables for 2 different purposes
    and you will get rid of the warning message.
    So far if you get the correct output of query then there is no need to worry.
    Edited by: kartikey on Dec 20, 2007 1:45 PM

  • Sql query data horizontally with sum and condition in a row

    I am trying to get data from the following query in a row with total but not succeed and getting error message. Please help and advise.
    Select empid,name,country,
    sum(case category when 'JOB' then sum(core+RR) else 0 end) as 'JOB-Sum',
    sum(case category when 'PRIVATE' then sum(core+PP) else 0 end) as 'PRIVATE-Sum',
    group by empid,name,country
    Note: Following query is good for getting result in one row but i have to put sum calculation with 'THEN' and want result in a row.
    SELECT ID, MAX(case when Col1 = 'Yes' then 1 else 0 end) AS Col1,
    MAX(case when Col2 = 'Yes' then 1 else 0 end) AS Col2
    FROM MyTable
    GROUP BY ID

    Please show some sample data and expected output.
    Regards,
    Rob.

  • BPC Netweaver dimension formula SUM and AGGREGATE

    Hello
    Does anybody knows the arguments we can use with SUM and AGGREGATE in a dimension formula in BPC NW.
    I would like to aggregate data on a hirarchy but not from leaf level only the child at a specific level (do an average at a certain level and then do an aggragate of the children at upper level).
    Any idea how to use CHILDREN with SUM or AGGREGATE ?
    Thanks
    Regards

    Hi Anne,
    Note [1550366|https://service.sap.com/sap/support/notes/1550366] solves part of your problem (in SP06), but these formula results will not roll up the hierarchy and you still cannot reference formula members within formulas, so you will not easily be able to aggregate the averages that you calculate.
    It would probably be better to calculate your averages in script logic and assign them to normal base members.
    Ethan

  • Conditional Sum and look at next record

    First off, here is an example XML structure
    &lt;DATASET&gt;
    &lt;DATASET_ROW&gt;
    &lt;DEPARTMENT&gt;1&lt;/DEPARTMENT&gt;
    &lt;FEE&gt;30&lt;/FEE&gt;
    &lt;DIVISION&gt;Displayed Title&lt;/DIVISION&gt;
    &lt;/DATASET_ROW&gt;
    &lt;DATASET_ROW&gt;
    &lt;DEPARTMENT&gt;1&lt;/DEPARTMENT&gt;
    &lt;FEE&gt;20&lt;/FEE&gt;
    &lt;DIVISION&gt;Displayed Title2&lt;/DIVISION&gt;
    &lt;/DATASET_ROW&gt;
    &lt;DATASET_ROW&gt;
    &lt;DEPARTMENT&gt;1&lt;/DEPARTMENT&gt;
    &lt;FEE&gt;40&lt;/FEE&gt;
    &lt;DIVISION&gt;Displayed Title3&lt;/DIVISION&gt;
    &lt;/DATASET_ROW&gt;
    &lt;DATASET_ROW&gt;
    &lt;DEPARTMENT&gt;2&lt;/DEPARTMENT&gt;
    &lt;FEE&gt;30&lt;/FEE&gt;
    &lt;DIVISION&gt;Displayed Title 5&lt;/DIVISION&gt;
    &lt;/DATASET_ROW&gt;
    &lt;DATASET_ROW&gt;
    &lt;DEPARTMENT&gt;2&lt;/DEPARTMENT&gt;
    &lt;FEE&gt;80&lt;/FEE&gt;
    &lt;DIVISION&gt;Displayed Title 6&lt;/DIVISION&gt;
    &lt;/DATASET_ROW&gt;
    &lt;DATASET_ROW&gt;
    &lt;DEPARTMENT&gt;3&lt;/DEPARTMENT&gt;
    &lt;FEE&gt;90&lt;/FEE&gt;
    &lt;DIVISION&gt;Displayed Title 7&lt;/DIVISION&gt;
    &lt;/DATASET_ROW&gt;
    &lt;DATASET_ROW&gt;
    &lt;DEPARTMENT&gt;3&lt;/DEPARTMENT&gt;
    &lt;FEE&gt;90&lt;/FEE&gt;
    &lt;DIVISION&gt;Displayed Title 8&lt;/DIVISION&gt;
    &lt;/DATASET_ROW&gt;
    &lt;DATASET_ROW&gt;
    &lt;DEPARTMENT&gt;4&lt;/DEPARTMENT&gt;
    &lt;FEE&gt;30&lt;/FEE&gt;
    &lt;DIVISION&gt;Displayed Title 9&lt;/DIVISION&gt;
    &lt;/DATASET_ROW&gt;
    &lt;/DATASET&gt;
    Is there any way to get a sum of a field grouped by two different fields? Example in my RTF I have a repeating group based on DIVISION which inserts section breaks. Using the example I have posted here what I have in my RTF template is a sum of FEE (assume there are multiple records for DIVISION though only 1 is shown here) that displays on every page for the current group. Each DIVISION is printed on its own page. However, at the end of each DEPARTMENT, I also need to print a summary total of the sum of FEE over all records for that DEPARTMENT on the same page as the last page of the last DIVISION.
    So far, I have been able to get it to do the subtotals for each DEPARTMENT as they are within the scope of my loop. The tricky part I am unsure of how best to go about doing is getting and displaying the conditional grand total. My initial idea was to use a variable and do it manually in my template but then I relaized I did not know how to find out if the next record was the first record in the next Department or not. In this case, I am hoping to stick within the realm of using straight SQL Query as my datasource because its already done. The other option I considered was nested loops and a data template but then I realized that I wasn't too sure about manually inserting the section breaks.
    Any thoughts?

    Yes, you can do that,
    Pass me the template and XML :)
    <?if:position() = last()?>
    Last Record
    <? end if ?>
    then display the sub-total for department at the last division.
    This link , gives you idea of , how to display at the last
    http://blogs.oracle.com/xmlpublisher/2008/08/continued.html
    Use
    xdofo:inline-total display-condition="last"

  • Using multiple 'and' conditions in a SQL query

    Is it possible to reduce the SQL required to query using multiple 'and' conditions, e.g. I have a query like the following:
    select stat.personal_id, appt.username, appt.password, apps.rgn_apt_id, apps.apy_apn_id
    from apy_ast_application_status stat, rgn_usr_user appt, rgn_aps_applications apps
    where stat.apy_apn_id = apps.rgn_apt_id
    and apps.rgn_apt_id = appt.rgn_apt_id
    and stat.application_completed is null
    and stat.application_started_date > '01-MAY-11'
    and stat.amount_paid is null
    and stat.personal_details = 'C'
    and stat.further_details = 'C'
    and stat.education = 'C'
    and stat.employment = 'C'
    and stat.personal_statement = 'C'
    and stat.choices = 'C'
    and stat.reference = 'C'
    and stat.student_finance = 'C'
    Is there a way, to reduce all the multiple 'and' queries, to be read from say one line? If you know what I mean.......

    Ah, Ok this looks nice, thanks very much. It doesn't quite run as is because the stat.amount_paid query value is 'is null', while the others are 'C'. I tried amending the relevant line to various versions of the following:-
    in (select 'is null' 'C','C','C','C','C','C','C','C' from dual)
    which doesn't work.
    I can get the following to work so I am assuming that the it is not possible to use different query values within the brackets of the 'in (select....' statement?
    select stat.personal_id, appt.username, appt.password, apps.rgn_apt_id, apps.apy_apn_id
    from apy_ast_application_status stat, rgn_usr_user appt, rgn_aps_applications apps
    where stat.apy_apn_id = apps.rgn_apt_id
    and apps.rgn_apt_id = appt.rgn_apt_id
    and stat.application_completed is null
    and stat.application_started_date > '01-MAY-11'
    and stat.amount_paid is null
    and (stat.personal_details, stat.further_details, stat.education,
    stat.employment, stat.personal_statement, stat.choices, stat.reference, stat.student_finance)
    in (select 'C','C','C','C','C','C','C','C' from dual)
    Thanks for everybodys help - the suggested alternatives seem so much more elegant

  • How do I accept the Terms and Conditions when trying to set up an Apple ID for the first time ( using my iphone)?

    I am trying to create an Apple ID by using the Itunes icon on my iphone 5s for the first time. It opens up a screen with the 54 pages of Terms and Conditions and it does not allow me to even accept the Terms and Conditions... no Accept option or place to click!
    The only option is to Send the terms and conditions via email... which also does not work...it keeps asking me to "try again"... Has someone else had this problem?

    Hello, Wyseup. 
    Thank you for visiting Apple Support Communities.
    Most likely this email address has been attempted to be setup as an Apple ID at some point.  You can reset your Apple ID password via the steps in the first article below.  If you do not have access to the email account, need assistance or are not receiving the password reset link, see the second article.
    Apple ID: If you forget your password
    http://support.apple.com/kb/ht5787
    Apple ID: Contacting Apple for help with Apple ID account security
    http://support.apple.com/kb/HT5699
    Cheers,
    Jason H.

  • Getting wrong values when using sum() and last() functions in aggregations.

    Hi..
    I created a request in presentation servicews it includes " employ id,name,organization.cost center,annul salary,haouly salary, head count". for employ 13 cost centers available so 13 annul salaries for 13 organizations.each has annul saari 10400,hourly salary 10.previously when i run the request with headcount not including salaries headcount is 1 for 13 rows. when head count is not included in the requst and ran request it gives for 13 rows salaries are 10,400,10 respectively. when i add the head count to the previous request the salaries become 135200,130 respectively. actual head for each organization is 1.in the requst it show as 13. the headcount field in business layes uses 'other sum(headcount),date last(headcount). i need it to same values for salaries after addition of
    headcount also.
    Thank you.
    Edited by: user10797474 on May 20, 2009 8:08 AM

    Did you already have a look in the log file to see the SQL which is sent to the DB?
    This might be a modeling issue in your RPD. Check if you have set the correct dimensionlevels for your facts.
    Regards
    John
    http://obiee101.blogspot.com/

  • My ipod touch screen is totally unresponsive and i have been using it under normal conditions. ihave tried the reset and restore but to no avail.everything works as it would normally do  on the screen.help pls????

    my ipod touch screen is totally unresponsive and i have been using it under normal conditions. ihave tried the reset and restore but to no avail.everything works as it would normally do  on the screen.help pls????

    Might want to post your question in the correct forum.  This is the iPHONE forum.

  • In the icloud settings, i am told i need to accept the terms and conditions to use icloud, but when i try to do so, i get a message "unable to connect to server". This has been going on for a week. There is no problem with either my wifi or cellular conne

    In the icloud settings, I am told I need to accept the terms and conditions to use icloud. However, when I click on "Terms and conditions", I get a message "unable to connect to server". This has been happening for a week now since I upgraded to iOS 7.06. There is no problem with my wifi or cellular connectivity, all other applications work perfectly. P.S.I have never used icloud before, but wish to do so now. How do I overcome this problem?

    Have you turned the iPad off then back on? That often helps with problems.

  • Can we use exceptions and conditions at the same time?

    can we use exceptions and conditions at the same time? Are there any dependencies between exceptions an conditions?

    Exceptions are used when there are some mistakes , or exceeds the supposed values, we can highligt that in different colours for enabling the validator to notice easily. In this we are giving conditions for considering the value as exceptions. suppose, if the values is out of the range -1 to +1 then exception.
    But conditions can be considered as the restrictions given in measure level also. So please elaborate what you meant by conditions

  • HT204053 i couldn't open new terms and conditions of icloud, and so i can't use the icloud on my device iphone 5, this problem appears, when I get new ios 7

    i couldn't open new terms and conditions of icloud, and so i can't use the icloud on my device iphone 5, this problem appears, when I get new ios 7

    Try download the Find My Friends app and signing in to accept the terms and conditions there.

  • I can't accept iTunes store terms and conditions using my iPhone...

    I can't accept iTunes store terms and conditions using my iPhone... It means there's no possibility to downoad any new app from the store...

    Have you tried to restore it?If you have important data,back it up and restore it after entering DFU Mode.OR TRY TO RESTART YOUR PHONE.Google DFU MODE if you dont understand.Cheers!!!

  • TS3988 I recently downloaded iOS 7 on my iPad but now can't get further than iCloud agreement. How do I get to use the iPad? it is stuck on the Terms and Conditions page!

    Greetings Friends!
    Could someone please help?!!!
    I cannot get my iPad to function... I recently downloaded (prompted) iOS 7. next, I forgot the ID for this iPad ... got confused ... now I asked for Email assistance but the iPad is stuck on the page for "Terms and Conditions".
    Please HELP!
    Rhont1996

    Hi Rhont1996!
    In order to troubleshoot this issue, you may need to restart or reset your iPad according to the instructions found here:
    iOS: Turning off and on (restarting) and resetting
    http://support.apple.com/kb/ht1430
    You may also need to go to your Safari settings to make sure you are not blocking cookies:
    Safari settings - iPad User Guide
    http://help.apple.com/ipad/7/#/iPadabb26b71
    After making sure your Safari settings allow cookies, you may need to force Safari to close according to the instructions found here to solidify the change:
    iOS: Force an app to close
    http://support.apple.com/kb/ht5137
    Thanks for using the Apple Support Communities. Have a good one!
    -Braden

Maybe you are looking for

  • Using JOptionPane to exit program & Using toString method

    Hello, In my program I have to use a toString method below public String toString(Hw1NCBEmployee[] e)         String returnMe = String.format(getStoreName() + "\n" + getStoreAddress() + "\n" + getCityState() +  "\nYou have " + getEmpCount() + "employ

  • Getting 1st of Month Previous To Current Month

    Hello, trying to get the first of the month previous to the current month. So if Sysdate is 6/10/20, then I want 5/1/2010 returned for criteria.. No idea how to go about this, any help is appreciated..

  • JSF, NetBeans and customizing of Standard Validation Errors

    Hello together, i want to use german Standard Validation Errors via a own .properties File: 1. Here is my faces-config.xml ( the entries are uncommented ! ): <faces-config> <application> <locale-config> <default-locale>de</default-locale> <supported-

  • Erased Firmware can't update since PC won't recognize pla

    I have a Zen Micro. My PC wasn't recognizing the device. I searched forums and found out about a problem with the firmware and the need for an update. The old firmware was deleted, but now I can't install the new firmware because the PC doesn't recog

  • Problem with sales order consumption

    Hi I hope someone can help?  I have a problem with consumption of sales orders in APO.  When a sales order comes across from R/3 it doesn't consume the forecast until a later sales order comes across, then the previous one consumes forecast.  So all