IF ELSE statement in BEX
Hi all,
I need to write a formula in a query using IF ELSE statements. Here is my senario
I need to write a IF ELSE statement to calculate a KF i.e., % variance of This year with last year sales (TY%LY) .Following are the conditions.
IF LY<0 then TY % LY should be (TY-LY)/LY * (-100)
IF LY>0 then TY% LY should be (TY-LY)/LY * (100)
IF LY =0 then TY%LY should be 100
IF LY=NULL (i.e., if store is closed last year we donu2019t pull record so LY will be empty) then TY%LY should be 100
IF TY=0 or NULL then TY%LY should be -100
So I tried writing as follow but getting errors
(LY<0)(TY-LY)/LY(-100) + (NOT(LY<=0))((TY-LY)/LY)100 + (LY==0)100 + NODIM(LY)100 + (TY==0)(-100) + NODIM(TY)(-100)
But it is giving errors. Can you please suggest me how to write that formula without effecting the current performance of the query.
Thanks in Advance,
Preethi
Hi Preethi,
I think that you can accomplish the desired results using the following formulas:
KEY FIGURE = NOT(F1=0) * F5 + (F1=0) * -100
F1 = NOERR(TY + 0)
F2 = NOERR(LY + 0)
F3 = NOERR( (F1-F2) / F2 ) * -100
F4 = F3 * -1
F5 = (F2<0) * F3 + (F2>0) * F4 + (F2=0) * 100
I hope it helps you.
Regards,
Maximiliano
Similar Messages
-
IF ELSE Statement in BEx Query based on the results
Hi experts,
I want to realize the following IF/ELSE statement in a BEx Query in respect to the result values
If the result of KF1 equals 0, than set the KF2 to 0, Else (KF1 NE 0) show the value of KF2
Background: I want to report the order backlog. In the example above we have an incoming order value of 23.700,80 EUR in periode 12.2013 and an turnover of 22.370,80 EUR in periode 01.2014. The order backlog in ST (KF1) is 1 ST (12.2013) - 1 ST (01.2014) = 0 ST. The order backlog in EUR (KF2) is 23.700,80 EUR (12.2013) - 22.370,80 EUR (01.2014) = 1.330 EUR. The Order and Invoice is finished, but we have an positive order backlog in EUR (reason: less turnover as incoming order).
For this case I want to realize the IF/Else statement to check if the oder backlog in ST = 0, if yes, than set the order backlog in EUR also to 0.
Any best practices?
Many thanks and best regards,
MichaelHi Suman,
thanks aigain for your reply!
I have tried your proposal before you have posted it.
In my special case the following if/else statement works successfully:
CKF = calculated key figure
Formula1 = (CKF1 == 0) * 0 + (CKF1 <> 0) * CKF2
In my case the CKF2 is the result value from "Incoming Order value" - "Turnover"
So I had to define a separate Formula (1:1 equals to CKF2) and then I was able to set "*CKF2" in the statement.
The statement CKF2 = (CKF1 == 0) * 0 + CKF2 is not possible (because it´s not possible to calculate from CKF2 itself).
Now it works
Best regards,
Michael -
IF THEN ELSE STATEMENT IN BeX Query designer
Hi,
I want to write a query as follows:
IF <Value a> is available THEN <Value a> ELSE <Value b>
I have written it as follows:
(X>0)X+(X<=0)Y
The problem with this equation is, in case X = 0(number Zero) then Y is not getting displayed. But In case X =NULL (or no values) then Y displayed. This is leading to inconsistency in final result. Please help in rectifying the formula incase it is incorrect or is it because of some program bug in BeX?
Regards
MadhavThis works for me...dont understand y its not working with u!!
it is simple:
(X<>0)X+(X==0)Y
If X is 0, then 0X + 1Y = Y
else
1X + 0Y = X.
What result you are getting in both cases?
as you thing,X value is may not be 0 in your case. It may be 0.00004...something like that...Set Decimal Places to 5 or 6 to X.
Message was edited by:
Muralidhar C -
If Then Else Statement in SAP R/3 BW
Hi,
Does anyone know how to create an If Then Else statement in BEX?
Thanks,
Mounika.Hi mounika,
do this way
If 'material number' > 0.
rslt = 'enter into table'.
else.
rslt = 15.
endif.
A True condition always evaluates to 1, a False condition evaluates to 0.
for more quieries in bw ..pls go through the link
http://sap.ittoolbox.com/groups/technical-functional/sap-bw
pls reward if helps,
regards. -
IF...ELSE.. STATEMENT in BEx Query Designer
Hi,
Why there is no IF, ELSE function in BEx Query Designer?
Assuming I need to write the following logic, how can it be accomplished?
IF (A=0 OR B=0)
THEN 0
ELSE IF ( B/A <0)
THEN ' *'
ELSE
B/A * 100
i.e.
if A or B is equal to 0, then display the value of 0
else if B is negative (as A is either 0 or positive), then display the following text: ' *'
otherwise, display the value of B/A * 100
Thanks!Hi,
You can achieve this by creating a new formula.
You have to use the boolean operations and mathematical functions. But we cannot display *. u have to display some value for that.
Khaja -
IF ELSE statement / CMOD Code in BEX Query
Hi
I have a requirement in Inventory flow.
Material stock value at the end of each quarter has to be calculator based on cycle count indicator. I have all the values on my cube.
In the report, Calender year and quarter is on the selection screen.
When user enters 2014 and Q2, Data for April, May and June are displaying on the report. But user want data only for June.
At the end of quarter 2 is June, so he wants only Material stock value at the end of June.
If a material stock level is changed in April and May and not changed in June, not data is available for June in my Cube.
In this case for Quarter 2, if June data is missing, it has to look for May data. Even if MAY data is missing, it will have to look for April.
Even if April data is missing, it will have to look for March data.
The result should be
Plant Q1 Q2 Q3 Q4
XYZ 100 100 100 100
If there is no change to stock level in April, May & June - at the end of Quarter 2, the stock value should be 100 as it was in end of Q1.
If no change was dont to stock level until December, the stock level should be 100.
Is there a way out using IF ELSE statements or through CMOD customer exit.
Regards,
Elango MurgesanHI Elango,
the user input on CALQuarter always would be Single value??or can we expect ranges as well?
if single value,
then we can achieve it by having one more dummy KF.
lets say. user input is Q2.
-> in your dummy KF, restrict the Calquarter/Calmonth to last quarter(i.e Q1)using customer exit and make the logic as you said above(last value based on calmonth).(make this KF hidden, as this is not required to display)
-> and in another KF restricted with Q2.Same logic, last value on Calmonth.((make this KF hidden, as this is not required to display)
and now you have 2 KFs in your report. So in a formula, you can have condition-> if Q2 KF is blank, then Q1KF, else Q2 KF.
Hope you are getting my idea.. Please try this and let us know.
** if Q1 also null, then we can extend customer exit logic to may be last one year, and having last value on based on calendar month, we can still achieve i guess.
Regards,
Sakthi. -
hi everyone
i need help
I'm trying to make if else statement in the sqldeveloper query
and my code us like ...
IF CHARGE_PRICE BETWEEN 10000 AND 20000
THEN
charge_apartment(1,600);
ELSIF CHARGE_PRICE BETWEEN 20000 AND 40000
THEN
charge_apartment(1,500);
ELSIF CHARGE_PRICE > 40000
THEN
charge_apartment(1,900);
ELSE
charge_apartment(1,650);
END IF;
now the question is how do i cover that part of code so the sqldeveloper query will know that I'm talking about an Apartments table...?
I dig around the net and so far all the info i got is relevant only for sql*Plus
so...
How can I do this at the query?
thanks in advance
Edited by: 885780 on Sep 16, 2011 4:04 PM
Edited by: 885780 on Sep 16, 2011 4:05 PMI'll explain myself again more clearly
if i', execute the command
execute Charge_Apartment(1,600)
so the right apartment is being charged with the right peice,
But!
if i'm execute
CASE
WHEN APARTMENT_SIZE < 10000 THEN Charge_Apartment(1,650);
WHEN APARTMENT_SIZE < 20000 THEN Charge_Apartment(1,600);
WHEN APARTMENT_SIZE < 40000 THEN Charge_Apartment(1,500);
ELSE Charge_Apartment(1,900);
END
I'm crashing with
Error starting at line 1 in command:
CASE
Error report:
Unknown Command
Error starting at line 2 in command:
WHEN APARTMENT_SIZE < 10000 THEN Charge_Apartment(1,650)
Error report:
Unknown Command
Error starting at line 3 in command:
WHEN APARTMENT_SIZE < 20000 THEN Charge_Apartment(1,600)
Error report:
Unknown Command
Error starting at line 4 in command:
WHEN APARTMENT_SIZE < 40000 THEN Charge_Apartment(1,500)
Error report:
Unknown Command
Error starting at line 5 in command:
ELSE Charge_Apartment(1,900)
Error report:
Unknown Command
Error starting at line 6 in command:
END
Error report:
Unknown Command
If someone can help me i'll be glad
Thanks in advance 4 all of you who helped so far ... -
Charactersitic values to be used in IFTHEN ELSE STATEMENT IN QUERY
scenario: i need to use the characteristic values(not the attributes) to be used in an IF THEN ELSE STATEMENT in query. so i created a formula variable for the characteritic of processing type replacement path, replace with key.The values are not fetched in the result and is displayed as X.
what should i replace with key,lable, constant or other options whereas my requirement is the all the values present in the characteristc should be used.
eg. if char name is xyz and has the values 1,2,3,4,5 till -
20.
then in a calculated key figure :(formulavariable =1)* kefig1keyfig2 +not(formulavariable =1)kef2keyfig3.
this formula variable should have all the values of the characteristic values ie 1,2,3---20.
2. how should i do get the values of characterstics values in the equation give me the steps in detail..
3. i do not want to use the attributes, though i tried initally while creating the formual variable i replaced with attribute value, there is was an error and there were no reult.
i tried to create char. variable for the characteristic of manual entr , not ready for input values and gave all the values 1,2,3 --20 as default values and then created formaul variable and repalce with the variable, however this characteristic variable is not at all displayed from the list of variables which will be displayed while creating the formula variable.
help me out.
Thankshi srini,
i have includedthe char in rows. i want you to explain in detail how to use these values in the if then else statement in query.
i have created a calculated key figure 2= (formual variable =1 & keyfig a =0)* keyfig1kefig2 +not(formual variable =1 & keyfig a =0)keyfig2 *calculated keyfig1.
so this formula variable of replacement path have ref. to then char. and with what value should it replace, key, name, external char or attribut etc so that i should get the values of the char from 1 to20.
i donot to repalce with the attribute. i just want the char. values and not thier attributes (1. description 2. the second attribute has the values say abc1,efg2,ghi3 for respective charteristic values.
ie
char value desc 2nd attrib
1 hi abc1
2 bye defg2
3 ciao ghi3 -
Looking for a best query for multiple IF Else statement in a single select
Hi
I want to run multiple IF Else statements in a single select SQL, each statement is one SQL operating on the same table, what is the best way to write this select SQL query ?
If it is PL/SQL, when i get the result from the first IF statement I will skip the remaining execution, and so on... Can any one help me on this.
Thanks in advance !!965818 wrote:
I Apologize, the information i have given might not be enough.
This is my scenario,
I am selecting set of rows from the table for the employee id. After selecting those records,
i need to go through the result list and check the condition 1, if it is met, i will return that employee record.
If that condition 1 is not met, then i need to go through the condition 2. If that is met, i will return that record.
Like wise, i have four conditions.
I am trying to achieve this in a single sql. If i am not clear, please let me know.Not fully clear yet, but the picture is better already. The thing with SQL is that you should stop thinking procedurally. Instead think in data sets.
For example if the task is:
Find all managers that work in sales.
Procedural thinking would work like this:
pseudo code
Loop over all employees that work in sales
for each row
check if it is a manager
if manager
then return record
else
do nothing
end
end loopThinking in datasets will result in a different logic
pseudo code
select all employees
where department = SALES
and job = MANAGERThis advantage here is that all the "Do nothing" loops are not needed. Those are already eliminated by the database.
So what is needed to help you? Give the full picture. What is your task that you try to solve. From a business perspective. -
How to use IF ELSE statement in one QUERY to MS ACCESS
System.out.println("Enter Final Exam: ");
int f = Integer.parseInt(input.readLine());
command.executeUpdate("UPDATE Students SET Final_Exam='"+f+"',Raw_score=(QT+MT+Final_Exam)/3 WHERE stud_name='"+stdID+"'");
command.executeUpdate("UPDATE Students SET Raw_score=(QT+MT+Final_Exam)/3 WHERE stud_ID='"+stdID+"'");
if (rsf==100)
command.executeUpdate("UPDATE Students SET Final_Grade=1.0 WHERE stud_ID='"+stdID+"'");
else if(rsf < 100 && rsf > 90)
command.executeUpdate("UPDATE Students SET Final_Grade=2.0 WHERE stud_ID='"+stdID+"'");
else
command.executeUpdate("UPDATE Students SET Final_Grade=5.0 WHERE stud_ID='"+stdID+"'");How can I shorten my code using a IF ELSE statement inside a single query or two? Or is it possible?
Edited by: ivatanako on Sep 28, 2007 11:55 PMSun has tutorial trail for JDBC, you might want to browse through that; you'll get more details and samples there than here. Here's the link to the section on PreparedStatement: http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html
People on the forum help others voluntarily, it's not their job.
Help them help you.
Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
(Yes I know it's on JavaRanch but I think it applies everywhere)
---------------------------------------------------------------- -
Hi guys i have a requirement where in i have condition as mention below...
If say X=0 then Y=0 and
if X>0 then y=1
where X is key figure value...to be compared ..
can any one suggest me the logic as to how i need to design this in the query..any option of using IF-ELSE statement...
an in the result if Y=0 then i should show as a * (star)..how can we do this in the query?
can any one suggest me a solution for this please..
Rgds
Shilpashipa,
please check these links
[Defining Exceptions|http://help.sap.com/SAPHELP_NW04S/helpdata/EN/43/21b4cd14cd06f4e10000000a422035/frameset.htm]
[Defining and Changing Exceptions|http://help.sap.com/saphelp_nw04/helpdata/EN/c2/f6843b49f6a40de10000000a11402f/content.htm] -
Error msg in IF ELSE statement in jsp page, Need help
Below is my code I am trying to execute, but keep getting an error:
Compilation error occured:
Found 1 errors in JSP file:
D:\\http\\proFolder\\student.jsp:130: Syntax: "}" inserted to complete StatementNoShortIf
<%if (assess.getNumberValue() > 0) {%>
<%if ((assess.getTotalCost(appForm)) <= (assess.getNumberValue())) {%>
<strong><%=assess.getTotalCost(appForm)%></strong>
<%}%>
<%}%>
<%else {%>
<%=assess.getTotalCost(appForm)%>
<%}%>Basically, What I am trying to do is follow this logic:
IF method getNumberValue() is greater then 0, then execute the second IF statement that
is, If method getTotalCost() is less then or equal to getNumberValue() then display value of method getTotalCost()
End Second IF
End First IF
Now if the First IF fails ( that is getNumberValue() is not gether then 0)
then execute the else statement
Could someone please guide me what I am doing wrong, and what would be the correct way of write the IF else code
Thanks,<% if (assess.getNumberValue() > 0) {
if ((assess.getTotalCost(appForm)) <= (assess.getNumberValue())) {
%>
<strong><%=assess.getTotalCost(appForm)%></strong>
<%
%>
<%
else {
%>
<%=assess.getTotalCost(appForm)%>
<%
%> -
it is possible to write something approaching an if..then..else statement in SQL with 'generalized' conditions in the if statement.
Attached is the query for the payment register, in which I've written a series of decode statements, one for each possible value of the payment code. The query works OK - however, its specific and as the number of paycodes expand (and they do), the report won't pick up the new paycode until the code is changed. More importantly, the report won't be correct until someone 'discovers' that a paycode is missing, which might take months.
If I were writing the equivalent of this series of decode statements in Focus, it would be something like this:
DEFINE.......
PAYMED/D12.2 = IF PAYMENT_CD LE 18
THEN PAYMENT_AMT
ELSE 0 ;
PAYIND/D12.2 = IF PAYMENT_CD GE 19 AND PAYMENT_CD LE 49
THEN PAYMENT_AMT
ELSE 0 ;
PAYEXP/D12.2 = IF PAYMENT_CD GE 70
THEN PAYMENT_AMT
ELSE 0 ;
PAYREC/D12.2 = IF PAYMENT_CD GE 50 AND PAYMENT_CD LE 69
THEN PAYMENT_AMT
ELSE 0;
END
IN SQL/PLUS:
SELECT ACCOUNT_NAME,
LOCATION_1,
CLMNT_LAST_NAME,
CLAIM_NBR,
DATE_OF_INJURY,
DATE_CHECK_REGISTER,
PAYEE_NAME_1,
PAYMENT_CD,
SERV_OFC,
CPO_CHECK_NBR,
PAYMENT_FORM,
DECODE(PAYMENT_CD, 20, PAYMENT_AMT, 21, PAYMENT_AMT,
22, PAYMENT_AMT, 23, PAYMENT_AMT, 25, PAYMENT_AMT,
26, PAYMENT_AMT, 27, PAYMENT_AMT, 28, PAYMENT_AMT,
29, PAYMENT_AMT, 30, PAYMENT_AMT, 31, PAYMENT_AMT,
32, PAYMENT_AMT, 33, PAYMENT_AMT, 34, PAYMENT_AMT,
35, PAYMENT_AMT, 36, PAYMENT_AMT, 37, PAYMENT_AMT,
39, PAYMENT_AMT, 40, PAYMENT_AMT, 41, PAYMENT_AMT,
42, PAYMENT_AMT, 43, PAYMENT_AMT, 44, PAYMENT_AMT,
45, PAYMENT_AMT, 46, PAYMENT_AMT, 47, PAYMENT_AMT,
48, PAYMENT_AMT, 49, PAYMENT_AMT, NULL) INDEMNITY,
DECODE(PAYMENT_CD, 0, PAYMENT_AMT, 1, PAYMENT_AMT,
2, PAYMENT_AMT, 3, PAYMENT_AMT, 4, PAYMENT_AMT,
5, PAYMENT_AMT, 6, PAYMENT_AMT, 7, PAYMENT_AMT,
8, PAYMENT_AMT, 9, PAYMENT_AMT, 10, PAYMENT_AMT,
11, PAYMENT_AMT, 12, PAYMENT_AMT, 13, PAYMENT_AMT,
14, PAYMENT_AMT, 15, PAYMENT_AMT, 18, PAYMENT_AMT,
17, PAYMENT_AMT, NULL) MEDICAL,
DECODE(PAYMENT_CD, 70, PAYMENT_AMT, 71, PAYMENT_AMT,
72, PAYMENT_AMT, 73, PAYMENT_AMT, 74, PAYMENT_AMT,
75, PAYMENT_AMT, 76, PAYMENT_AMT, 77, PAYMENT_AMT,
78, PAYMENT_AMT, 79, PAYMENT_AMT, 80, PAYMENT_AMT,
81, PAYMENT_AMT, 82, PAYMENT_AMT, 83, PAYMENT_AMT,
84, PAYMENT_AMT, 85, PAYMENT_AMT, 86, PAYMENT_AMT,
87, PAYMENT_AMT, 88, PAYMENT_AMT, 89, PAYMENT_AMT,
90, PAYMENT_AMT, NULL) EXPENSES,
DECODE(PAYMENT_CD, 50, PAYMENT_AMT, 51, PAYMENT_AMT,
52, PAYMENT_AMT, 53, PAYMENT_AMT, 54, PAYMENT_AMT,
55, PAYMENT_AMT, 56, PAYMENT_AMT, 57, PAYMENT_AMT,
58, PAYMENT_AMT, NULL) RECOVERIES,
DECODE(PAYMENT_FORM, 'N', PAYMENT_AMT, NULL) NONCASH,
DATE_FROM_SERVICE,
DATE_THRU_SERVICE
FROM &INPUT_TABLES
WHERE &SECURITYCOND
DATE_OF_PAYMENT BETWEEN :START_DATE AND :END_DATE
ORDER BY LOCATION_1, CPO_CHECK_NBR
As you can see, this is both much easier to write and covers the possibility of expansion of paycodes (expansions always fit in these defined ranges).
My question is, then, is it possible to write something like this in SQL and, if so, could you give me some sample code? (I'm one of those people who learn best from looking at the code as opposed to a set of instructions)Here is one way you could do it.
Create a table that has columns like:
Payment_code varchar2(2),
Effective_Date Date,
Payment_type varchar2(20),
Expiration_Date Date)
Payment type for example could be
I- indemnity
M- medical
R- recovery
E- expenses
Let the table name for example be PAYMENT_CODE.
The select query would look like
SELECT ACCOUNT_NAME,
LOCATION_1,
CLMNT_LAST_NAME,
CLAIM_NBR,
DATE_OF_INJURY,
DATE_CHECK_REGISTER,
PAYEE_NAME_1,
PAYMENT_CD,
SERV_OFC,
CPO_CHECK_NBR,
PAYMENT_FORM,
DECODE(p.payment_type,'E',PAYMENT_AMOUNT,0) expenses,
DECODE(p.payment_type,'I',PAYMENT_AMOUNT,0) indemnity,
DECODE(p.payment_type,'M',PAYMENT_AMOUNT,0) Medical,
DECODE(p.payment_type,'R',PAYMENT_AMOUNT,0) recoveries,
DECODE(PAYMENT_FORM, 'N', PAYMENT_AMT, NULL) NONCASH
FROM &INPUT_TABLES,
PAYMENT_CODE P
WHERE P.PAYMENT_CODE = SOMEINPUT_TABLE.PAYMENT_CODE
and other conditions
The idea is to group all the payment codes into a few groups to reduce the clutter. If there is ever a change to the payment code, you could modify the table and it will be reflected in your select query. -
Java If/Then/Else Statement
Hello,
Just wondering if it is possible to call one java file from within another.
I'm thining wiht an if.then/else statement similar to
If x==true
then run file1.java
else run file2.java
any examples of this, or if it is even possible would be appreciated.This is something like what I would do.
public class FileRunner {
public static void main(String [] args) {
if ( args[0].equals("file1") {
File1 file1 = new File1();
file1.init() //method you define in File1 that runs everything that would've been in the File1's main method
} else if (args[0].equals("file2") {
File2 file2 = new File2();
file2.init() //method you define in file2 that runs everything that would've been in the File2's main method
} else {
System.err.println("Invalid argument");
System.exit(1);
java.exe FileRunner.class file1
java.exe FileRunner.class file2The other method is to start a new jvm from within java, but that gives you less control than this imo. -
How to total 2 colums with an -If then else- statement each
Hello,
I have 2 colums A en B who generate data based on an “If then else” statement.
Colum A
<?xdofx:if (OMZET_YTD_VJ )!='' then ((OMZET_YTD_VJ) * (BM_YTD - BM_YTD_VJ)) div 100 else 0 end if?>
Colum B
<?xdofx:if (BM_YTD)!='' then ((BM_YTD) * (OMZET_YTD - OMZET_YTD_VJ)) div 100 else 0 end if?>
Colum C needs to be the sum of both. Who can help me?
Thanks a lot.Can you send me the RTF template and xml file to [email protected]? I can take a look and try to help.
Thanks,
Bipuser
Maybe you are looking for
-
I deleted several .mov files a while back that were encrypted into a .dmg file. Using Disk Drill, I was able to recover 5 of these files, roughly 500-900 MB each and successfully moved them to my desktop. When I try to open the .dmg file, the dreaded
-
HoW DO i DOWNLOAD PHOTOS AND CONTACTS FROM THE COMPUTER TO MY NEW IPHONE?
How do I download photos and contact off of Icloud from computer to my new Iphone ?
-
Is not defined in this session
SELECT cycle_flag, sequence_name FROM ALL_SEQUENCES I picked 'record_SEQ' sequence from the listing. select record_SEQ.Currval from dual; ==> ORA-08002: sequence record_SEQ.Currval is not defined in this session. where is the problem ?
-
Using TEXT EDITOR in a Container
Hi, I have one question about the scroll bar. I don´t know how can i control the scroll bar. Someone know which method can i use? Regards, Fred
-
How do you remove the password from a pages document?
Hello, for the first time, I created a password for a pages document, and I blocked the document too. I've tried to unblock and I can't, and I've tried to delete the password but I can't neither. Every time I try, when I close the document tells me,