Query if-then-else logic with calculation

Hello,
I want to calculate within a BEX-formula.
I have two key-figures:
- Quantity
- Value
The logic should be like this:
IF Value > 0 THEN Value / Quantity ELSE 0
( / means: divided)
How can I reach this?
The URL
http://help.sap.com/saphelp_nw70ehp1/helpdata/de/e3/e60138fede083de10000009b38f8cf/frameset.htm
does not help me.
Thanks for your help,
Thomas

That is the way to perform if then else...
As long as boolean operations returns 0 or 1 you must play with that in order to get the desired result.
In case you have DIV problems you can use this operator:
NDIV0 (x): Is equal to 0 with division by 0, otherwise x.
   NDIV(<Expression>)
Delivers 0 if the expression named in <Expression> gives a division by 0 in
the calculation. Otherwise, the result is the value of the expression.
Is used to
  - Avoid the output of an error message
  - Continue calculating with a defined result
Please give an example if I am missing something.
Regards,
Sebastian,.

Similar Messages

  • How to do IF THEN  ELSE logic in Workflow?

    I need to do "if then else" logic in Workflow. The key part of the probem is that there are several "else" (elsif) possibilities, so I can't use a Boolean or Yes/No as a return result code. When I use a function, I can't see a way to "check" the value before it passes to a next process. HELP!

    Whether you are using a function as your comparator or the Standard WF Compare Operators, this can be done. I will explain two scenarios, one with your own written functions as the comparator and the other using the standard Compare Text function.
    Create a PL/SQL procedure that returns a boolean. In this procedure you would pull two attributes from the workflow, the test case and the value you want to compare to. You would check to see if they are equal and return true, otherwise false. I do not know what you are trying to compare in your if statement, but whatever it is, if its true, return true, otherwise false.
    Now in the workflow, you would put a couple of these in your process diagram representing each if statement. Set the two (or more) attributes in the Node Attributes tab of each function node to the values you want to compare. For the first node, have the <true> transition go to whatever you want done and then to an END node. Have the <default> or <false> transition point to the next function node you have. Do the same for each one except at the last one, its only transition would be <default> and that would go to END. This way if the first function resolves true, it will do whatever should be done and then skip the rest of the conditions. If its false, it will go to the next conditional. The last one will be gotten to only if every other conditional was false that would be your final else statement.
    To do this with the Compare Text option, have the same set up in your workflow diagram exception have the <EQUALS> be your true path and the <DEFAULT> transition go to the next compare text node.
    -->O-{default}->O-{default}->O->default
         |                 |                 |             |
        true           true            true           |
         |                 |                 |             |
      doWork     doWork     doWork      else
         |                 |                 |             |
          ---------------->---------------->------------|
                                                          |
                                                      end

  • If then Else using DAX Calculation

    Hi all, new to DAX. I am trying to replicate a Oracle SQL column using DAX functions in SSAS Tabular.
    My Oracle column is defined like below:
    If STATE_CODE Not in('A','B','C','D') 
            And Not (substr(PK_ID,4,2) = 'XY' And DIV_CODE in('YU','SD')) Then
             CNT = 1;
          Else
             CNT = 0;
    Any ideas how to start? Should i use DAX Switch function ?
    Thanks,
    TAG

    We have IF and Switch Function Available in DAX .
    You can use any of one.
    IF(logical_test>,<value_if_true>, value_if_false)
    For Switch you can use below;
    SWITCH(TRUE(),
    booleanexpression1, result1,
    booleanexpression2, result2,
    else
    Just create calculated column in Cube and add this logical IF/Switch function there.
    Or If you want to calculate this at query level using DAX then you can follow below Query.
    Evaluate
    ADDCOLUMNS
    TableName,
    , "calculated column"
    ,IF( Logical,Truecondition,False Condition)
    Thanks
    Please Mark This As Answer or vote for Helpful Post if this helps you to solve your question/problem. http://techequation.com

  • My 'IF THEN ELSE' possible with graphical mapping tool ?

    Hello,
    Being new to XI I got into some issues during message mappings.
    I want to say:
    if externrole = 'BY'
       then saprole = 'AG' and sappartner = externpartner.
    else.
    if externrole = 'DP'
       then saprole = 'WE' and sappartner = externpartner.
    endif.
    I try this with the graphical mapping. Is this possible ?
    How do I link two standard 'if' functions together.
    Robert

    Hi Robert,
    This is possible by graphical mapping. Do the mapping in the following way.
    ->Use if with else
      *if--->externrole EqualsS AG
      *then->AG[Constant]
      *Else->o\p of the following IF w\o Else.
      *O\p-->saprole
    ->If without Else
      *if--->externrole EqualsS DP
      *then->WE[Constant]
    ->For sappartner map it to externalpartner.
    Hope this helps.
    Regards,
    Jesse.
    Message was edited by: Jesse George

  • Problem with if-then-else using BI Answers dataset

    Hi, I'm having issues using the if-then-else logic with a BI Answers dataset. I'm running two versions of a report - one that access the SH schema tables directly, and one that uses a BI Answers dataset based on the SH schema.
    My problem is with the if-then-else operator. It works fine against the relational tables when I use the following syntax:
    <?xdofx:if CUST_GENDER = 'M' then 'Mr.' else 'Ms.' end if?>
    However, when I go against a BI Answers report, the name of the field changes from CUST_GENDER to Customers._Cust_Gender_. If I make an exact find and replace on the if-then-else code, it doesn't work (nothing at all displays)
    <?xdofx:if Customers._Cust_Gender_ = 'M' then 'Mr.' else 'Ms.' end if?>
    Can anyone help?
    Thanks,
    Scott

    Is it possible that any of the fields have null values?  If so, see my blog post about null handling in Crystal for more information:  What is Null and Why is it Important for Crystal Reports | SAP BI BLOG
    -Dell

  • Problem with IF THEN ELSE in RTF template

    HI ALL,
    I have two layouts in the RTF template. Based on the parameter value it has to show the value.
    For example if P_State='United States' then first layout should come. else second one should come.
    I tried to use the IF Then else logic through the form field but i am getting error.
    Please help on this to get it.
    Regards
    Boopathi

    You can do that.
    i guess, the syntax you are using is wrong.
    please refer documentation or this forum for choose:
    Use choose statement. it s better.
    Or send me the template to my id in my profile. or upload it here http://apps2fusion.com/forums/viewforum.php?f=60

  • Using if the else logic in regards to a select statement for a report

    Hi all,
    I've a question regarding if then else logic in Oracle.
    I'm developing a report application which contains 3 selectlists
    - ProductGroup - SubGroup - Manufacturer
    Each one containing several values. And are based on eachother, meaning if you select an item from the PG list, you only get the SG items regarding the PG item you've choosen before. The process logic should be as the following:
    When a user selects one item from for example the PG list, the query will be:
    select * from x where PG = :P_PG
    and the report displays all the items in the PG category selected
    The other two bindvariables would be null as the user didn't pick them
    If he then proceeds and selects one item from the SG list, the query would be:
    select * from x where PG = :P_PG and SG = :P_SG
    and the report displays all the items in the PG and SG category selected
    If he then proceeds and selects one item from the MA list, the query would be:
    select * from x where PG = :P_PG and SG = :P_SG and MA =:P_MA
    and the report displays all the items in the PG and SG and MA category selected
    Now, I've read some documentation about the decode function, but I can't figure it out, please help.
    Peter

    Okay, Chet, have set it up on htmldb, so you can see my problem, will go in high detail, it is not producing what I want. Example on htmldb:
    DEMO/test
    http://htmldb.oracle.com/pls/otn/f?p=33229:6
    Defenitions:
    3 LOV's, namely:
    - LOVPG - select distinct productgroep, productgroep pg from plijst
    - LOVSG - select distinct subgroep, subgroep sg from plijst where productgroep = :P6_LOVPG
    - LOVLE- select distinct leverancier, leverancier le from plijst where productgroep = :P6_LOVPG and subgroep = :P6_LOVSG
    3 Selectitems with submit, namely:
    - :P6_LOVPG
    - :P6_LOVSG
    - :P6_LOVLE
    Report region select statement:
    select * from plijst where (productgroep = :P6_LOVPG or :P6_LOVPG IS NULL) and (subgroep = :P6_LOVSG or :P6_LOVSG IS NULL) and (leverancier = :P6_LOVLE or :P6_LOVLE IS NULL)
    Branch to:
    Branche to page on submit after processing
    What it should do is:
    When you select an item from the first selectlist, productgroep, the report should show all rows containing the specified productgroep.
    When the user selects the next item in the subgroep selectlist, the report should show all rows containing the previously selected prodctgroup and the just selected subgroep.
    When the user selects the final item , the report should show all rows based on all three selected itemvalues, productgroep, subgroep, leverancier.
    The problem is that with this setup the report is only generated after the final selectlist choice of the user. But the user should see a report before that, going deeper into the structure. Hope, you see my problem?
    Sincerely,
    Pete

  • IF THEN ELSE in DATA TEMPLATE NOT IN RTF

    Hi,
    Can any one tell me How to Implement IF THEN ELSE or DECODE or CASE Logic in a DATA TEMPLATE not in RTF
    as I saw loads of Post about implementing them in RTF not in the Template itself.
    I have a requirement please click this below for the Detailed Version of this Post, Else Please Just give me a Snippet from which i can Implement the IF THEN ELSE Logic in a DATA TEMPLATE( the .xml file) bu please not via a RTF not using PL/SQL Package
    Logic to select Report name based on User's input.
    Thanks
    vasanthanand

    Hello
    I am looking to do the same type of thing did you ever get an answer without having to use a RTF format perhaps in another forum or through investigation?

  • If then else in update query

    Hello,
    I was hoping anyone could provide ideas on the best way to do an update query based on an if then else statement I am using Oracle 11 on a linux server. I am writing within a perl script. I've researched online and saw some examples using case. Below is the basic query logic I am trying to implement. I would really appreciate any suggestions.
    Thanks,
    JC
    If the MAINT_CENTER IN ('ENOC1CENTER','PMCTGAAHSDC','ATTCSPCRT01','ATTCSPCWS01','NTNLWHS4NSA') AND CAC1=’S’ and substring(CKT_ID,4,2) IN ('KQ','KR','KS','KP','L1','L2','L3','VL') and askme_temp.CKT_ID = heci.CKT_ID then SUBPRODUCT =’IPAG’
    ELSE If the MAINT_CENTER IN ('ENOC1CENTER','PMCTGAAHSDC','ATTCSPCRT01','ATTCSPCWS01','NTNLWHS4NSA') AND CAC1=’S’ and substring(CKT_ID,4,2) IN ('KQ','KR','KS','KP','L1','L2','L3','VL') AND REGION=’SE’ then SUBPRODUCT =’METRO_E’
    ELSE If the MAINT_CENTER IN ('ENOC1CENTER','PMCTGAAHSDC','ATTCSPCRT01','ATTCSPCWS01','NTNLWHS4NSA') AND CAC1=’S’ and substring(CKT_ID,4,2) IN ('KQ','KR','KS','KP','L1','L2','L3','VL') then SUBPRODUCT =’OPT_E_MAN’

    Hi,
    Welcome to the forum!
    CASE sounds like a good idea to me.
    For example:
    UPDATE     table_x
    SET     subproduct = CASE
                   WHEN  askme_temp.CKT_ID = heci.CKT_ID
                         THEN  'IPAG'
                   WHEN  region          = 'SE'
                         THEN  'METRO_E'
                         ELSE  'OPT_E_MAN'
                   END
    WHERE     maint_center     IN ( 'ENOC1CENTER'
                      , 'PMCTGAAHSDC'
                      , 'ATTCSPCRT01'
                      , 'ATTCSPCWS01'
                      , 'NTNLWHS4NSA'
    AND   cac1                  = 'S'
    AND   SUBST (ckt_id, 4, 2)  IN ('KQ', 'KR', 'KS', 'KP', 'L1', 'L2', 'L3', 'VL')
    AND   ...
    ;CASE expressions are evaluated in the order in which you write them, so if askme_temp.ckt_id = heci.ckt_id (whatever those things are), subproduct will be set to 'IPAG'. It won't matter whether region is 'METRO_E' or not; if the 1st condition is TRUE, the first THEN value is returned, and the other WHEN expressions aren't even evaluated.
    What do you want to do if none of those conditions are met?
    Any conditions that are common to all the rows being UPDATEd can be put in the WHERE clause; they don't have to be repeated in the CASE expression.
    Remember, MERGE is often more convenient to use than UPDATE.
    Edited by: Frank Kulash on Jul 27, 2011 3:23 PM

  • How to write IF-THEN-ELSE in query (syntx)

    Dear Experts,
    As the decode syntx is Oracel's, is there any syntx could be used for IF-THen-Else function in query generator?
    Thanks.
    Emily

    Morning, Gouri,
    It works!!  Thanks very much!
    BTW, in Inventory menu, the report 'Inventory Posting  List, does it pull data from table 'OINM' ?
    It looks like OINM does not link with tables of ODLN (PL/delivery) and OPOR (PO), is it correct?
    If I would like link OINM to ODLN and OPOR, which table interrelated between them??
    Pls kinldy asdvise.
    Thanks in advance.
    Emily

  • Issue with calculating Top 20 % in Query Designer

    Hai
    I am working on Query designer 7.0 where I need to design a report which has 4 parts. The first 3 parts displays the Items with Top 20 Inventory Value with 3 respective divisions for 6 months . Now the 4th part is to display Top 20% of inventory Value.
    So in this report I need to take the Total Inventory and calculate the Top20 % of the items. Hence in this report I need to refer to the top 20 value of 3 divisions. So I cant jus give one condition. So I tried the replacement path for Items with restriction to other queries and created the variables. But I cant use these varaibles in the structures of rows or columns. It gives an error that this variable cant be used in Structure.
    Please do help me in refering the top 20 values of 3 divisions for 6 months and do a calculation to display the % in my 4th report.
    I will assign points for any kind of help provided

    If you can design all those in One query than you can have it...
    It seems now your aim is just to take result for 3 queries and use it in 4th query...
    But if you can figure out defining all 3 Divisions and restriction in Same Query and then put the DISPLAY OPTION = HIDE = do not display
    and then use their result to display you will achieve what you want to....
    for e.g.
    Jan 07-----Feb 07 -
    Mar 07 -
    Dec 07
    Division 1-- Item 1 -
    Inv 1 -
    Inv1.........................DO NOT DISPLAY
    Item2 -
    Inv2 -
    Inv2..........................DO NOT DISPLAY
    Item3 -
    Inv3 -
    Inv3..........................DO NOT DISPLAY
    <i><b>----
    Item20 -
    Inv20 -
    Inv20</b></i>........................DISPLAY ONLY
    Division 2-- Item 1 -
    Inv 1 -
    Inv1......................DO NOT DISPLAY
    Item2 -
    Inv2 -
    Inv2........................DO NOT DISPLAY
    Item3 -
    Inv3 -
    Inv3........................DO NOT DISPLAY
    <b><i>----
    Item20 -
    Inv20 -
    Inv20</i></b>....................DISPLAY ONLY
    Division 3-- Item 1 -
    Inv 1 -
    Inv1</b>.......................DO NOT DISPLAY
    Item2 -
    Inv2 -
    Inv2.......................DO NOT DISPLAY
    Item3 -
    Inv3 -
    Inv3.......................DO NOT DISPLAY
    <i><b>----
    Item20 -
    Inv20 -
    Inv20</b></i>.........DISPLAY ONLY
    THEN you will have result
    Division -
    Jan07 -
    Feb 07 -
    Marc 07
    div1 -
    Total inv/sum(top20) -
    Total inv/sum(top20) -
    Total inv/sum(top20)
    div2 -
    Total inv/sum(top20) -
    Total inv/sum(top20) -
    Total inv/sum(top20)
    div3 -
    Total inv/sum(top20) -
    Total inv/sum(top20) -
    Total inv/sum(top20)

  • Nested if-then-else with double condition

    Hi everybody, I tried to see on the forum how to build a complex if-then-else statement....but I didn't still find an answer
    So, I'll explain my situation:
    First I have to check if the field PROJ_DT_TO is null or not and then the language parameter:
    1. if the field PROJ_DT_TO IS NULL then I have to check the language parameter:
    a) if this last one is equal to 'English' I want to write inside my template 'Today',
    b) if instead is equal to 'Greek' I want to write 'Σήμερα'
    2. else if the field PROJ_DT_TO IS NOT NULL, again, I have to check the language parameter:
    a) if this last one is equal to 'English' I have to write <?format-date:PROJ_DT_TO;'MMMM yyyy'?>
    b) if instead is equal to 'Greek' I have to write <?format-date-and-calendar:PROJ_DT_FR;‘MMMM yyyy’;'GREGORIAN';'Europe/Athens'?>
    I used the following syntax...but it didn't work...
    <?choose@inlines:?>
    <?when@inlines:PROJ_DT_TO=''?>
    <?xdofx:if $p_language = 'Ελληνικά' then 'Σήμερα' else if $p_language = 'Αγγλικά' then 'Today' end if?><?end when?>
    <?otherwise@inlines:?>
    <?xdofx:if $p_language = 'Ελληνικά' then <?format-date-and-calendar:PROJ_DT_FR;‘MMMM yyyy’;'GREGORIAN';'Europe/Athens'?> else if $p_language = 'Αγγλικά' then <?format-date:PROJ_DT_TO;'MMMM yyyy'?> end if?>
    <?end otherwise?>
    <?end choose?>
    The first piece, until the first <?end when?> instruction works....it's the <?otherwise@inlines:?> and the rest which doesn't work.....
    If, instead, I use (without reaching my goal):
    <?choose@inlines:?>
    <?when@inlines:PROJ_DT_TO=''?><?xdofx:if $p_language = 'Ελληνικά' then 'Σήμερα' else if $p_language = 'Αγγλικά' then 'Today' end if?><?end when?>
    <?otherwise@inlines:?>
    <?format-date:PROJ_DT_TO;'MMMM yyyy'?><?end otherwise?>
    <?end choose?>
    I see the date PROJ_DT_TO even if always in the date format 'MMMM yyyy'
    Anybody knows how can I rewrite my statement in order to reach the if-then-else situation I metioned above ?
    Thanks in advance
    Best Regards
    Alex

    Hi Vetsrini, thaks for your answer and your hint !!
    I tried your code, but without the command 'when@inlines' doesn't work...
    So I tried this :
    <?choose@inlines:?>
    <?when@inlines:PROJ_DT_TO=''?>
    <?xdofx:if $p_language = 'Ελληνικά' then 'Σήμερα' else if $p_language = 'Αγγλικά' then 'Today' end if?>
    <?end when?>
    <?otherwise@inlines:?>
    <?format-date:PROJ_DT_TO;'MMMM yyyy'?>
    <?end otherwise?>
    <?end choose?>
    and It works..
    But, look at this ! I discovered on the manual that inside the Preferences it's possible to set the Report Locale with the language you want.....and if I set my Report Locale in Greek, using the code above I correctly see all dates in Greek....but ALWAYS !!
    I need to see dates in Greek or English dinamically according to the value of the parameter p_language passed inside the template at the beginnig (<?param@begin:p_language?>).
    Even if inside the code there is the double condition ($planguage = 'Ελληνικά' or $p_language = 'Αγγλικά') for the two cases PROJ_DT_TO='' or PROJ_DT_TO !='', I see ALWAYS dates in the language set inside the Locale Report....
    Is there a way to manipulate the Report Locale Setting and make it dinamic ?
    Thanks in advance
    Alex
    So this preference is static, even if inside my report I have the parameter p_language I can see the data and headings with

  • Creating Query in Production with Calculated key figures

    Hi BW Experts,
    Can u pls let me know that in case of Production System when we are allowing users to create reports with Adhoc Web Query Designer and using CKF + RKF
    (Calculated key Figure) which is already transported to Production in a specific Package, Is Production system will allow to save report?
    Pls sugges how to solve this problem ..to give permission for users to create reports in production server with CKF RKF?
    Thanks in advance

    rsa1 -> transport conection -> object changeability button -> Set query elements as everything changeable.
    If you want to refine this you have to do by authorizations.

  • Procedure with out parameter in if-then-else condition

    Hi,
    I want to fetch the out parameter of a procedure inside another procedure that has if-then-else condition.
    <<Proc1_start>>
    if ..
    then <<proc2_>> --- with out parameter
    end if;
    <<proc1_end>>
    How to do this...
    Thanks.

    Ummm, the same way you would do it anywhere else?
    Declare variable in proc1 to hold the output of proc2 and then call proc2.
    John

  • Can i change BI Query before loading it to BO using some if than else logic

    Hi guys
    In my requirement I have a BI query which the users want to run in BO now. Now the requirement is that they want to change some values in the BI query after the BI query has run based on some u201Cif than else logicu201D for each row.
    So my question is can BO modify a BI query. Is there some place I can write an abap routine between the BI query and the BO Report.
    Thanks

    Hi Adnan, in CR you can create Formula Fields, and you can include IF THEN ELSE statements there. This won´t modify the BI query, but´ll modify the results you see in CR (I believe this is what you want)
    Here, you have information about formula fields, CR 2008 User Guide in chapter 22
    You can do, something like this:
    IF {Tabla.Campo}=1
    THEN "AAA"
    ELSE "BBB"
    Hope this helps,
    Liliana

Maybe you are looking for

  • Printing problem on HP 8550

    One of our users is having problems printing a PDF from an HP 8550. The PDF was created in Acro 8, compatible back to 5. The user trying to print the PDF is opening and printing it from Acro 7. It is a 2 page PDF. The first page prints, but instead o

  • ISE 1.2 corrupted sponsor portal

    Hi, since I started to use ISE sponsor portal it showes me wrongly, see attached screenshot. I tried various browsers, but the problem is the same. Other pages are okay, just the main with guest users has problem. Looks like it happened after upgrade

  • Question marks at end of each line in messages sent with 10.4.6 mail

    Some Outlook users are finding ?s at the end of each line in my emails sent from 10.4.6. I did not have this problem in 10.3.9. The problem appears to be resolved when I choose UTF-8 message encoding. There appears to be no way to make Mail automatic

  • Ipod classic won't hold charge

    My apple ipod classic which is just a yr or two old won't hold a charge.  The battery icon has a lightning bolt in it so it says its charging but it won't hold a charge.  Any ideas?

  • HT5858 Where can I find a signal strength capability to check my WiFi network?

    Is there a download package to use for measuring the WiFI signal strength from my Airport Extreme?