Calculating liquidation - percentages with subqueries
Hi,
I have a query a sql statement as follows, which I am using to query an oracle database:
SELECT
EXTRACT(YEAR FROM "CLIENT_TH"."CREATED_DATE") AS LOAD_YEAR,
EXTRACT(MONTH FROM "CLIENT_TH"."CREATED_DATE") AS LOAD_MONTH,
CONCAT(CONCAT(EXTRACT(MONTH FROM "CLIENT_TH"."CREATED_DATE") , '-'), EXTRACT(YEAR FROM "CLIENT_TH"."CREATED_DATE") ) AS LOAD_MONTHNAME,
EXTRACT(YEAR FROM "DOC_HDR_TH"."CREATED_DATE") AS PAYMENT_YEAR,
EXTRACT(MONTH FROM "DOC_HDR_TH"."CREATED_DATE") AS PAYMENT_MONTH,
CONCAT(CONCAT(EXTRACT(MONTH FROM "DOC_HDR_TH"."CREATED_DATE") , '-'), EXTRACT(YEAR FROM "DOC_HDR_TH"."CREATED_DATE") ) AS PAYMENT_MONTHNAME,
SUM("DOC_HDR_TH"."TOTAL_GROSS"*-1) AS PAYMENT_AMOUNT,
"CLIENT_TH"."SPARE_CHAR_05" AS CLIENT_NAME,
"CLIENT_TH"."SPARE_CHAR_21" AS CLIENT_CODE
FROM
"SL"."CLIENT_TH" "CLIENT_TH" INNER JOIN
"SL"."TRAN_TH" "TRAN_TH" ON ("CLIENT_TH"."CLIENT_ID"="TRAN_TH"."CLIENT_ID") INNER JOIN
"SL"."DOC_LINK_TH" "DOC_LINK_TH" ON ("TRAN_TH"."TRAN_ID"="DOC_LINK_TH"."TRAN_ID") INNER JOIN
"SL"."DOC_HDR_TH" "DOC_HDR_TH" ON ("DOC_LINK_TH"."DOC_ID"="DOC_HDR_TH"."DOC_ID")
WHERE
"CLIENT_TH"."SPARE_CHAR_01" LIKE 'SBH/%') AND
("DOC_HDR_TH"."DOC_TYPE" NOT IN ('ADJ', 'Adjustment', 'ADMIN FEE', 'AOE FEE', 'ARREARS', 'CHARGE APP FEE', 'CLI', 'CO FEES', 'COSTS', 'CWO', 'DM', 'FEES', 'HCEO Fees', 'IJADJ', 'INTEREST', 'INV', 'JUDGEMENT COSTS', 'LATE PAYMENT COMP', 'OSB ADJ', 'SET WRITE OFF', 'SET WRITE OFF', 'WARRANT COSTS', 'WARRANT FEE')) and
TRUNC("DOC_HDR_TH"."CREATED_DATE") BETWEEN TRUNC(ADD_MONTHS(SYSDATE,-12),'MM') AND SYSDATE-1AND
TRUNC("CLIENT_TH"."CREATED_DATE") BETWEEN TRUNC(ADD_MONTHS(SYSDATE,-24),'MM') AND SYSDATE-1
GROUP BY
"CLIENT_TH"."SPARE_CHAR_05",
"CLIENT_TH"."SPARE_CHAR_21",
EXTRACT(MONTH FROM "CLIENT_TH"."CREATED_DATE") ,
EXTRACT(YEAR FROM "CLIENT_TH"."CREATED_DATE"),
EXTRACT(MONTH FROM "DOC_HDR_TH"."CREATED_DATE"),
EXTRACT(YEAR FROM "DOC_HDR_TH"."CREATED_DATE")
This transposes into the following outcome:
Payment Month
Jun-12 Jul-12 Aug-12
Load Date
Jun-12 100.12 200.00 300.00
Jul-12 300.00 400.00
Aug-12 500.00
This is working perfectly.
However, where I am having the problem is creating a liquidation batchtracker, where I want the outcome to look something like the following
Payment Months since Load
M1 M2 M3 M4 M5
Load Date
Jun-12 0.01% 0.02% 0.2% 0.3% 0.4%
July-12 0.02% 0.04% 0.4% 0.3%
Aug-12 0.01% 0.02% 0.2%
Sept-12 0.01% 0.02%
Oct-12 0.01%
The code I have so far is:
SELECT
CONCAT(CONCAT(EXTRACT(MONTH FROM Payments.LOAD_DATE) , '-'), EXTRACT(YEAR FROM Payments.LOAD_DATE) ) AS LOAD_MONTHNAME,
Original.ORIGINAL_BALANCE as ORIGINAL_BALANCE
FROM
(SELECT
"CLIENT_TH"."CLIENT_ID",
SUM("DOC_HDR_TH"."TOTAL_GROSS") AS ORIGINAL_BALANCE
FROM
"SL"."CLIENT_TH" "CLIENT_TH" INNER JOIN
"SL"."TRAN_TH" "TRAN_TH" ON ("CLIENT_TH"."CLIENT_ID"="TRAN_TH"."CLIENT_ID") INNER JOIN
"SL"."DOC_LINK_TH" "DOC_LINK_TH" ON ("TRAN_TH"."TRAN_ID"="DOC_LINK_TH"."TRAN_ID") INNER JOIN
"SL"."DOC_HDR_TH" "DOC_HDR_TH" ON ("DOC_LINK_TH"."DOC_ID"="DOC_HDR_TH"."DOC_ID")
WHERE
"CLIENT_TH"."SPARE_CHAR_01" = 'SBH/73020000003657' and
"CLIENT_TH"."SPARE_CHAR_01" LIKE 'SBH/%' AND
"DOC_HDR_TH"."DOC_TYPE" IN ('INV', 'ARREARS')
GROUP BY
"CLIENT_TH"."CLIENT_ID") Original LEFT OUTER JOIN
(SELECT
"CLIENT_TH"."CLIENT_ID",
"CLIENT_TH"."SPARE_CHAR_01" AS REFERENCE,
"CLIENT_TH"."CREATED_DATE"AS LOAD_DATE,
"DOC_HDR_TH"."CREATED_DATE" AS PAYMENT_DATE,
"DOC_HDR_TH"."TOTAL_GROSS"*-1 AS PAYMENT_AMOUNT,
"CLIENT_TH"."SPARE_CHAR_05" AS CLIENT_NAME,
ROUND(MONTHS_BETWEEN("DOC_HDR_TH"."DOC_DATE","CLIENT_TH"."CREATED_DATE") ) AS LIQUIDATION_MONTH
FROM
"SL"."CLIENT_TH" "CLIENT_TH" INNER JOIN
"SL"."TRAN_TH" "TRAN_TH" ON ("CLIENT_TH"."CLIENT_ID"="TRAN_TH"."CLIENT_ID") INNER JOIN
"SL"."DOC_LINK_TH" "DOC_LINK_TH" ON ("TRAN_TH"."TRAN_ID"="DOC_LINK_TH"."TRAN_ID") INNER JOIN
"SL"."DOC_HDR_TH" "DOC_HDR_TH" ON ("DOC_LINK_TH"."DOC_ID"="DOC_HDR_TH"."DOC_ID")
WHERE
"CLIENT_TH"."SPARE_CHAR_01" like 'S%' and
("DOC_HDR_TH"."DOC_TYPE" NOT IN ('ADJ', 'Adjustment', 'ADMIN FEE', 'AOE FEE', 'ARREARS', 'CHARGE APP FEE', 'CLI', 'CO FEES', 'COSTS', 'CWO', 'DM', 'FEES', 'HCEO Fees', 'IJADJ', 'INTEREST', 'INV', 'JUDGEMENT COSTS', 'LATE PAYMENT COMP', 'OSB ADJ', 'SET WRITE OFF', 'SET WRITE OFF', 'WARRANT COSTS', 'WARRANT FEE')) and
TRUNC("DOC_HDR_TH"."DOC_DATE") BETWEEN TRUNC(ADD_MONTHS(SYSDATE,-12),'MM') AND SYSDATE-1) Payments on (Payments."CLIENT_ID" = Original."CLIENT_ID")
WHERE
Payments.REFERENCE like 'S%'
I would really appreciate any help that anyone can give me.
Many thanks,
Sammy
Edited by: 998145 on 04-Apr-2013 12:42
Edited by: 998145 on 05-Apr-2013 02:31
Hi,
Let me see if I can somehow start again. So, I have a piece of code (Payments Query), which selects total payments grouped by load month/year and payment month/year. The resulting table looks as follows:
LOAD_MONTHNAME PAYMENT_MONTHNAME PAYMENT_AMOUNT CLIENT_NAME CLIENT_CODE
5-2012 6-2012 30,000 V
3-2012 4-2012 10,000 V
10-2012 11-2012 40,000 V
5-2012 6-2012 5,000 C The code that gives me the above dataset is as follows:
SELECT
CONCAT(CONCAT(EXTRACT(MONTH FROM "CLIENT_TH"."CREATED_DATE") , '-'), EXTRACT(YEAR FROM "CLIENT_TH"."CREATED_DATE") ) AS LOAD_MONTHNAME,
CONCAT(CONCAT(EXTRACT(MONTH FROM "DOC_HDR_TH"."CREATED_DATE") , '-'), EXTRACT(YEAR FROM "DOC_HDR_TH"."CREATED_DATE") ) AS PAYMENT_MONTHNAME,
SUM("DOC_HDR_TH"."TOTAL_GROSS"*-1) AS PAYMENT_AMOUNT,
"CLIENT_TH"."SPARE_CHAR_05" AS CLIENT_NAME,
"CLIENT_TH"."SPARE_CHAR_21" AS CLIENT_CODE
FROM
"SL"."CLIENT_TH" "CLIENT_TH" INNER JOIN
"SL"."TRAN_TH" "TRAN_TH" ON ("CLIENT_TH"."CLIENT_ID"="TRAN_TH"."CLIENT_ID") INNER JOIN
"SL"."DOC_LINK_TH" "DOC_LINK_TH" ON ("TRAN_TH"."TRAN_ID"="DOC_LINK_TH"."TRAN_ID") INNER JOIN
"SL"."DOC_HDR_TH" "DOC_HDR_TH" ON ("DOC_LINK_TH"."DOC_ID"="DOC_HDR_TH"."DOC_ID")
WHERE
("CLIENT_TH"."SPARE_CHAR_01" LIKE 'BH/%' OR
"CLIENT_TH"."SPARE_CHAR_01" LIKE 'SBH/%') AND
("DOC_HDR_TH"."DOC_TYPE" NOT IN ('ADJ', 'Adjustment', 'ADMIN FEE', 'AOE FEE', 'ARREARS', 'CHARGE APP FEE', 'CLI', 'CO FEES', 'COSTS', 'CWO', 'DM', 'FEES', 'HCEO Fees', 'IJADJ', 'INTEREST', 'INV', 'JUDGEMENT COSTS', 'LATE PAYMENT COMP', 'OSB ADJ', 'SET WRITE OFF', 'SET WRITE OFF', 'WARRANT COSTS', 'WARRANT FEE')) and
TRUNC("DOC_HDR_TH"."CREATED_DATE") BETWEEN TRUNC(ADD_MONTHS(SYSDATE,-12),'MM') AND SYSDATE-1AND
TRUNC("CLIENT_TH"."CREATED_DATE") BETWEEN TRUNC(ADD_MONTHS(SYSDATE,-24),'MM') AND SYSDATE-1
GROUP BY
"CLIENT_TH"."SPARE_CHAR_05",
"CLIENT_TH"."SPARE_CHAR_21",
EXTRACT(MONTH FROM "CLIENT_TH"."CREATED_DATE") ,
EXTRACT(YEAR FROM "CLIENT_TH"."CREATED_DATE"),
EXTRACT(MONTH FROM "DOC_HDR_TH"."CREATED_DATE"),
EXTRACT(YEAR FROM "DOC_HDR_TH"."CREATED_DATE")I am then pivoting the above data returned by the sql in excel to display the data as below, with the LOAD_MONTHNAME as Row Labels and the PAYMENT_MONTHNAME as column labels.
PAYMENT_MONTHNAME
LOAD_MN 4-2012 5-2012 6-2012 7-2012
4-2011 £226.00 £226.00 £191.00 £235.00
5-2011 £361.00 £303.50 £213.50 £278.00
6-2011 £231.83 £240.84 £150.00 £35.00
7-2011 £122.06 £88.82 £190.63 £158.80 The above all works perfectly. The next step I need to take (and is the part that I am having trouble with) is that I need to calculate the above cash values as a % of the total balance that was loaded in the month.
The below code is what I have under a seperate query (Balance Query) to return the balances for each load_month:
SELECT
"CLIENT_TH"."SPARE_CHAR_05",
CONCAT(CONCAT(EXTRACT(MONTH FROM "CLIENT_TH"."CREATED_DATE") , '-'), EXTRACT(YEAR FROM "CLIENT_TH"."CREATED_DATE") ) AS LOAD_MONTHNAME,
SUM("DOC_HDR_TH"."TOTAL_GROSS") as INVOICE_AMOUNT
FROM
"SL"."CLIENT_TH" "CLIENT_TH" INNER JOIN
"SL"."TRAN_TH" "TRAN_TH" ON ("CLIENT_TH"."CLIENT_ID"="TRAN_TH"."CLIENT_ID") INNER JOIN
"SL"."DOC_LINK_TH" "DOC_LINK_TH" ON ("TRAN_TH"."TRAN_ID"="DOC_LINK_TH"."TRAN_ID") INNER JOIN
"SL"."DOC_HDR_TH" "DOC_HDR_TH" ON ("DOC_LINK_TH"."DOC_ID"="DOC_HDR_TH"."DOC_ID")
WHERE
"DOC_HDR_TH"."DOC_TYPE"=N'INV') AND
("CLIENT_TH"."SPARE_CHAR_01" LIKE N'BH/%' OR
"CLIENT_TH"."SPARE_CHAR_01" LIKE N'SBH/%')
GROUP BY
"CLIENT_TH"."SPARE_CHAR_05", EXTRACT(MONTH FROM "CLIENT_TH"."CREATED_DATE") ,EXTRACT(YEAR FROM "CLIENT_TH"."CREATED_DATE")This returns the below data:
CLIENT_NAME LOAD_YEAR LOAD_MONTH LOAD_MONTHNAME INVOICE_AMOUNT
A 2011 7 7-2011 £20,000.00
A 2011 8 8-2011 £30,000.00
A 2011 9 9-2011 £3,000.00What I basically need to do is calculate the first payments query with the above balance query to show the liquidation percentage, and I am not sure how to combine the two queries. So, for example, for Client A, the payments that came in for the accounts with a LOAD_MONTHNAME OF 7-2007 were:
PAYMENT_MONTHNAME
LOAD_MN 4-2012 5-2012 6-2012 7-2012
7-2011 £122.06 £88.82 £190.63 £158.80 (taken directly from the Payments query results)
These then need to be calculated for each monthname against the balance loaded in 7-2011 which is £20,000 (from Balance Query).
I hope this now explains it better and thanks so much all of you for your help in looking at this.
Thanks again,
S
Edited by: 998145 on 04-Apr-2013 16:49
Similar Messages
-
The App Store indicates there is a Software Update that appears to include the HP Printer Software Update 3.0 and iTunes 12.0.1
Unfortunately, the software update fails to install. Instead, it just sits there 'Calculating' for days with no progression on the status bar of the overall update.
The update buttons of both the HP Printer Software Update 3.0 and iTunes 12.0.1 are both greyed out, with no progress bar.
Not sure of what the issue is, there is no warning or error dialog box that appears or any indication of an application that may be interfering with the install.
Any advice?
MacBook Pro (17-inch, Early 2011) 2.3 GHz Core i7, 4GB RAMThanks for the suggestion. I wanted to install the individual updates but because I had settings to automatically download and install updates, whenever I opened the App Store, the system would try to download and install, preventing me from canceling the update to execute each application update one at a time.
After changing the settings from automatically downloading and applying updates, followed by a restart. I was able to open the App Store and run each individual update.
Thanks again. -
In Report Builder 3.0, I have the following custom code entered:
Public Function SafeDivide(Numerator as String, Denominator as String) as String
Try
If Numerator = “” or Denominator = “” then
Return “-“
End if
If Numerator = “-“ or Denominator = “-“ then
Return “-“
End If
If CDbl(Numerator) =0 or CDbl(Denominator) = 0 then
Return “-“
End if
If IsNothing(Numerator) or IsNothing(Denominator) then
Return "-"
End if
Return Val( ( (CDbl(Numerator) / CDbl(Denominator) )*100 ) )
Catch
Return "-"
End Try
End Function
I call the custom code in the cell with the following equation:
=Code.SafeDivide(sum(Fields!TY_UNITS.Value)-sum(Fields!LY_UNITS.Value),sum(Fields!LY_UNITS.Value))
I have the format for the cell set to 0.00%, but it’s not being followed.
I want the result to be formatted as a Percentage, but instead I get values like:
-78.9473684210
80
300
-100
I have the format for the cell set to 0.00%, but it’s not being followed.
How do I do use the custom code and format for a percentage with 2 decimals?Hi AngP,
After testing the issue in my local environment, I can reproduce it. Based on my research, I find this issue is caused by the type of Units_VAR_Percentage cell is string, while the type of CDbl(Parameters!Var_Threshold.Value) is double, so they cannot be
compared.
To fix this issue, we can add a hidden column (Textbox91) next to the Units_VAR_Percentage column, and type =(sum(Fields!TY_UNITS.Value)-sum(Fields!LY_UNITS.Value)) /sum(Fields!LY_UNITS.Value) as the expression. Then use the expression below to control the
BackgroundColor:
=iif(iif(reportitems!Units_VAR_Percentage.Value=CStr(format(reportitems!Textbox91.Value,"0.00%")),reportitems!Textbox91.Value,0)>CDbl(Parameters!Var_Threshold.Value),"Yellow","PaleTurquoise")
If there are any other questions, please feel free to ask.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
Plz help me about my Iphone 5s battary life is so bad without using in the night keep on after 6 hours morning when i open battary % lose 60 percentage with out using plz help me..
Maximize iPhone Battery (iOS7):
1) Turn off Airdrop: Control Center >AirDrop > Off
2) Limit background app refresh. Turn it off for applications such as Google/Facebook.Settings > General > Background App Refresh
3) Turn off automatic updates: Settings > iTunes & App Store > Updates and Apps (off)
4) Unneccessary Location Services: Settings > Privacy > Location Services > System Services > Off (uncheck as needed)
5) Turn off Paralax: Settings > General > Accessibility > Reduce Motion
6) Siri, and her 'raise to speak.' Turn it off: Settings > General > Siri > Raise to Speak
7) Exclude items from Spotlight search as needed: Settings > General > Spotlight Search
8) Remove unneccessary notifications: Settings > Notification Center > None (per app basis)
9) Make sure auto-brightness is on, or reduce the brightness to 25% or less if desired.Settings > Wallpapers & Brightness
10) Use Still backgrounds only: Settings > Wallpapers & Brightness> Choose Wallpaper
11) Fetch email instead of "Push": Settings > Mail, Contacts, Calendar > Fetch New Data >Push(off) & Fetch every 15 minutes
12) Disable LTE if needed: Settings > Cellular > Enable 4G/LTE (OFF)
13) Reduce Autolock: Settings > General > Auto-Lock > 1 Minute
14) Disable Vibrations with Ring: Settings > Sounds > Vibrate on Ring (off)
15) Close Applications regularly: Double Tap Home Button > Swipe up on App to close -
Why update with subqueries does not have cost and cardinality?
There is update.
update test t1 set dummy = (select dummy from test2 t2 where t1.id = t2.id);Both tables which have actual statistics. Each has 1000 rows. And column ID have values from 1 to 1000 in each table.
This is explain plan
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | UPDATE STATEMENT | | 1000 | 13000 | 426 (9)| 00:00:01 |
| 1 | UPDATE | TEST | | | | |
| 2 | TABLE ACCESS FULL| TEST | 1000 | 13000 | 426 (9)| 00:00:01 |
|* 3 | TABLE ACCESS FULL| TEST2 | 1 | 13 | 426 (9)| 00:00:01 |
Predicate Information (identified by operation id):
3 - filter("T2"."ID"=:B1)We can see here, that Oracle consider subquery within update as once-executed subquery.
This is runtime plan
| Id | Operation | Name | Starts | E-Rows | A-Rows |
| 1 | UPDATE | TEST | 1 | | 0 |
| 2 | TABLE ACCESS FULL| TEST | 1 | 1000 | 1000 |
|* 3 | TABLE ACCESS FULL| TEST2 | 1000 | 1 | 1000 |
Predicate Information (identified by operation id):
3 - filter("T2"."ID"=:B1)Why first plan does not have cost in step 1?
Does Oracle always not understand that update with subqueries will performed as NL or filter? In other words that step 3 will executed many times.
Or it is my bug (or what?)?793769 wrote:
Does Oracle always not understand that update with subqueries will performed as NL or filter? In other words that step 3 will executed many times.
Or it is my bug (or what?)?It's not possible to say whether this is a bug or a deliberate choice.
Because of "subquery caching" (see http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/ ) the optimizer cannot predict how often the subquery will have to run. So possibly it shows nothing rather than showing the best or worst cases or a pure guess.
Regards
Jonathan Lewis -
i am new to abap. how to calculate the percentage of some amount field. and i want to pass that value to smartform. how to do that, and how to conver amount to discription i mean i want to display 3000 as three thousand plz help me .
Hi,
If you want the calculated percentage to SmartForm then you have to create the structure and then pass that structure to the SmartForm Import parameters.
The logic for calculating the percentage remains the same as we have been doing so far in other Pro Languages.....
HTH,
Regards,
Dhruv Shah -
Battery problem after enabling battery percentage with ibackupbot
My battery on my iPod touch 5g drains faster after I added the battery percentage with ibackupbot. Does anyone who did this have the same problem?
Before my battery drain to 93% of constant usage ( wifi on,checking email, browsing safari, etc ) in about 1 hour and 25 minutes; now it goes to 93% in 45 to 50 minutes.
Also when I charge my iPod it gets only to 95% and stops charging, and when I unplugged it, it reads 99%.
Please help if you guys know how to fix this..Restore to the iPod to factory settings/new iPod.
-
Hi SAP gurus,
I want check spool request number in percentage with transaction sp01,Iam getting with transaction rz20 percentage of spool.I want check it with sp01.Please help me.
BR,
kkHello KK,
This is BI forum and I think you will get best reply at Application server forum: /community [original link is broken]
Regards,
Frank -
Why doesnt the Ipod touch 5th gen have Battery Percentage with IOS 7?
I read that the Ipod touch 5th gen will have battery percentage with IOS 7. But so far it doesnt. Just wanted to know if this was a lie or if something happened and apple decided to remove it.
"Battery percentage in status bar added to iPod Touch (5th generation)"
I seen this
and i have seen pictures of the Ipod touch with the percentage next to the battery on the apple website. -
Problem of percentage with calculated KF
Hi,
I am trying to get the percentage share of a calculated KF. its something like this
col -> RKF1 RKF2 CKF(RKF1 + RKF 2)
row1:392150 0 392150
row2:410925 101298 512223
%(row1%A row2): 95% -- 95%
The last % value should be 76% but it doesn;t take the total for the calculation. How can i correct this??
Regards,
SujaiHi,
Please use Formula Collision in your report on this % calculation.
This will solve your problem.
-Vikram -
Percentage with calculated Key figure in queru designer
Hi,
I have this problem with query designer.
I want to calculate a share over sub total in a query with 3 characteristic exploded: one in vertical (project)
and 2 in horizzontal (quarter and year). I am using query designer 7.0.
I have created a calculated KF with function CT% but, instead to have the percentege over subtotal, I have the percentege over total.
This is the example of what I would like to get:
quarter 1 2
year 2007 2008 2007 2008
Cost % cost Cost % cost Cost % cost Cost % cost
Project
Total 27365 100% 30155 100% 29300 100% 29875 100%
PRJ 1 820 2,99% 1100 3,65% 930 3.17% 860 2,88%
Could anyone help me ?
Thank you !
Bye.
ElenaHi,
create two restricted keyfigs:
KF1 restricted to one of your 0CALYEAR
KF2 restricted to the other year
Create a formula or CKF, KF3 = KF1 - KF2
Implement your TOP N condition on KF3
hope this helps...
Olivier. -
How can I add decimals to my calculator? Percentages as well?
I am building a simple calculator app. I have implemented my calculator this way: I have the viewcontroller.h and .m, I also have my "CalculatorBrain.h and .m" That is where I implement the addition and substraction, multiplication. I use the symbol or the text of the button to read it and calculate the value. The question is, if I have 1.5 plus 1.5, it says the answer is 2. It only takes the 1 and the 1. How do I add decimals? Also, if possible, how would I do percentages?
This is my Calculator Brain.m:
#import "CalculatorBrain.h"
const NSString *Delete = @"D";
@implementation CalculatorBrain
- (void)setOperand:(double)anDouble
operand = anDouble;
- (void)performWaitingOperation
if ([@"+" isEqual:waitingOperation]) {
operand = waitingOperand + operand;
} else if ([@"-" isEqual:waitingOperation]) {
operand = waitingOperand - operand;
} else if ([@"×" isEqual:waitingOperation]) {
operand = waitingOperand * operand;
} else if ([@"÷" isEqual:waitingOperation]) {
if (operand) {
operand = waitingOperand / operand;
- (double)performOperation:(NSString *)operation;
if ([operation isEqual:@"√"]) {
operand = sqrt(operand);
} else {
[self performWaitingOperation];
waitingOperation = operation;
waitingOperand = operand;
return operand;
@end
And this is my View Controller.m. Any suggestions?:
#import "CalculatorViewController.h"
@implementation CalculatorViewController
- (CalculatorBrain *)brain
if (!brain) {
brain= [[CalculatorBrain alloc] init];
return brain;
- (IBAction)digitPressed:(UIButton *)sender;
NSString *digit = [[sender titleLabel] text];
if (userIsInTheMiddleOfTypingANumber) {
[display setText:[[display text] stringByAppendingString:digit]];
} else {
[display setText:digit];
userIsInTheMiddleOfTypingANumber = YES;
- (IBAction)operationPressed:(UIButton *)sender;
if (userIsInTheMiddleOfTypingANumber) {
[[self brain] setOperand:[[display text] doubleValue]];
userIsInTheMiddleOfTypingANumber = NO;
NSString *operation = [[sender titleLabel] text];
double result = [[self brain] performOperation:operation];
[display setText:[NSString stringWithFormat:@"%g", result]];
- (void) runTimer;
// This starts the timer which fires the showActivity
// method every 0.5 seconds
myTicker = [NSTimer scheduledTimerWithTimeInterval: 0.5
target: self
selector: @selector(showActivity)
userInfo: nil
repeats: YES];
- (void)showActivity;
NSDateFormatter *formatter =
[[NSDateFormatter alloc] init];
NSDate *date = [NSDate date];
// This will produce a time that looks like "12:15:00 PM".
[formatter setTimeStyle:NSDateFormatterMediumStyle];
// This sets the label with the updated time.
[clockLabel setText:[formatter stringFromDate:date]];
// Implement viewDidLoad to do additional
// setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
// This calls the runTimer method after loading
// SimpleClockViewController.xib
[self runTimer];
// CalcController.m
// SimpleCalc
// Created by Chris Ball ([email protected]) on 1/17/08.
// Copyright 2008, Chris Ball, Strainthebrain.Blogspot.Com.
// All rights reserved.
- (IBAction)resetEverythingPressed:(UIButton *)sender;
if (userIsInTheMiddleOfTypingANumber) {
[[self brain] setOperand:[[display text] doubleValue]];
userIsInTheMiddleOfTypingANumber = NO;
NSString *operation = [[sender titleLabel] text];
double result = [[self brain] performOperation:operation];
[display setText:[NSString stringWithFormat:@"0", result]];
@end
Oh, by the way, it tells the time. And if you want a screenshot, so you can see how it works out...For percentages, first make sure the number is < 0, then multiply it by 100, add a % sign and you're done
double displayValue = [display.text doubleValue];
if(displayValue < 0)
displayValue *= 100;
[display setText:[@"%" stringByAppendingFormat:@"%g", displayValue]]; -
Percentages with Level Based Measures
Hi All,
I am creating a report with the following 3 columns: product, count of customers, % of total customers.
The count of customers is calculated using count distinct (customer_id). Total count of customer is calculated by setting count(distinct customer_id) at the total level of the product hierarchy.
Now when I try creating my report when I try to show product by count of customers/total count of customers. I get 0. When i create a report to show product, count of customers, total count of customers, I see the correct value.
Can someone please tell me how I can view the correct % value.
Thanks,
NikitaActually, rather than using the CAST function, to get the decimal values for your percentage, multiply the quotient by 100.0 instead of 100 and this will work.
-
Formula for calculating aggregate percentage and percenatge of gender
hi all
i have a sp from which i get result columns gender,percentage,studentcount,year
my sp is like this..
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[usp_GetState]') AND type in (N'P'))
DROP PROCEDURE usp_GetState
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[usp_GetState]
( @ExamYear Smallint
,@ExamType Nvarchar(10)
AS
BEGIN
SET NOCOUNT ON;
WITH cte_Schools AS
SELECT
[Foreign]= CASE WHEN M.Zone ='F' THEN 'Y' ELSE 'N' END
,CASE WHEN M.Zone ='F' THEN UPPER(C.CountryName) ELSE UPPER(S.StateName) END StateName
,COUNT( DISTINCT M.SchoolCode) Schools
,SUM( M.Nos) Students
FROM rptFinalResultSummaryMaster M
LEFT OUTER JOIN State S ON M.StateCode=S.StateCode AND M.Zone=UPPER(LEFT(S.Zone,1))
LEFT OUTER JOIN Country C ON S.CountryId= C.CountryId
WHERE M.Year=@ExamYear AND M.CourseCode=@ExamType
GROUP BY CASE WHEN M.Zone ='F' THEN 'Y' ELSE 'N' END
,CASE WHEN M.Zone ='F' THEN UPPER(C.CountryName) ELSE UPPER(S.StateName) END
SELECT
SlNo=ROW_NUMBER() OVER(PARTITION BY [Foreign] ORDER BY StateName)
,[Foreign] ,StateName, Schools, Students
, Percentage = (Students/(SELECT SUM(Students)*1.000 FROM cte_Schools))*100
FROM cte_Schools
ORDER BY [Foreign],StateName
END
GO
now..i wrote formula for percentage and when i connected this sp to my rdl where i took tablixi gave percentage value to gender and total percentage column
gender(column group)
total
number percentage
passcategory
this is my tablix format
my output looks like
boys girls
total
number(percentage)
passcategory1 (percenatge) 21 (40.38) 43 (56.75)
64(48.56)
passcategory2 (percenatge) 11 (21.15) 10 (13.51) 31(17.33)
passcategory3 (percentage) 20 (38.46) 21 (28.37) 41(33.41)
total (percentage)
52(xxx) 74 (xxx) 136 (100%)
i'm not getting thegender percentage properly for girls and boys total percentage of boys and girls coming correctly but individual percentage is not properly coming...that's because in sp i gave calculation for only total percenatge ..how can i calculate
the individual percentage of girls and boys in single column...so that i can place in gender column in tablix..and i can retrieve individual percentgaes of girls and boys seperately as shown in output..
please reply..its urgent
thanks in advance..
luckyplease reply..its urgent
Here is a tip: if you want to tick off people from helping you, you should absolutely include "urgent" in your post. That's a good way to encourage people to move to the next post. I did see this one earlier today, but did not have the time.
Anyway, I cannot really make out heads or tails of your question. Your output takes about gender, but I cannot see it in the output from the query, which appears to group by "Foreign" and StateName. How does the boys and girls get into the picture?
And for that matter that "totals" column?
Erland Sommarskog, SQL Server MVP, [email protected] -
Hi, I was looking up in the 「How to Auto Scale」 document
http://azure.microsoft.com/en-us/documentation/articles/cloud-services-how-to-scale/
and got stuck in the below paragraph, the part that describes how to calculate the
average percentage of CPU usage.
==========
All instances are included when calculating the average percentage of CPU usage and the average is
based on use over the previous hour. Depending on the number of instances that your application is using, it can take longer than the specified wait time for the scale action to occur if the wait time is set very low. The minimum time between scaling actions
is five minutes. Scaling actions cannot occur if any of the instances are in a transitioning state.
==========
Does any one know the microsoft`s definition of 「All Instance」 ?
Whether the virtual machines that are shut down but has been set into auto scaling group count as one of them?
The question is that the response time, the data shows up in the management portal delays a lot comparing to the
real time. I was wondering if the definition of the calculation described above is truly what the user`s want or not.
I`m all ears to any information. Thanks in advance !!Hello Tomo Shimazu,
Instance is a presence of a service eg :- VM is an instance. Copy of VM is another instance which is 2 instances of VM.
Although Microsoft’s pricing model is readily available and even offers a simple calculator (http://www.windowsazure.com/en-us/pricing/calculator/advanced/) to assist
in the process, it may be difficult to know how much of each resource you will need to get an estimate.
To understand on calculating the compute instances and the VM size, let’s first take a look at the VM role sizes offered by Microsoft.
The prices per month for each, at the time of writing, are $30, $90, $180, $360, $720 from ExtraSmall to ExtraLarge respectively. So with the exception of the
transition from ExtraSmall to Small, going to the next size VM is exactly twice the cost, which, is mirrored in the increase of resources you get at each level. With each step, CPU Cores, Memory, Disk Space, and Bandwidth are all doubled from the previous.
If this is the case, then, is there any advantage to any one of these over the others? The answer is yes. In the majority of cases, the best bet will be to go with the small instance, with the reason being that because all of these resources scale equally
to cost it is possible to achieve the exact equivalent to a larger VM simply by increasing the number of instances. For example 8 small instances is equivalent to one ExtraLarge instance, with the advantage of the fact that when not needed these small instances
can be turned off and will cost nothing.
By hosting the application in this manner, it increases the effectiveness of the number one reason that a business would transition to the cloud anyway – Scalability.
Obviously 16 smaller instances can be more finely adjusted to the application’s usage than 2 ExtraLarge can. If traffic gets higher or lower than expected, two Small Instances can be added at $180/mo for the time that they are running, versus adding another
ExtraLarge for $720/mo.
The only exception to using the smallest instance, is in the case of the ExtraSmall, which offers only 1/20 of the bandwidth of the Small, making it only feasible
for very lightly accessed applications or, more likely, a QA environment.
From this point, it becomes much easier to estimate the compute instance requirements of migrating the application to Windows Azure. Take the current server(s)
total resources (CPU, RAM, etc) and find how many Small instances it would take to recreate it. This gives a good starting point, however, remember that these instances can be turned on and off to meet demand, and beyond the first instance, there is no charge
when the instances are off. This can lead to significant cost savings, and is the primary incentive to migrating to the cloud.
For azure pricing information, refer
pricing details.
If you still unclear about pricing and billing, you may raise a service request with billing team
here
Hope this helps.
Regards,
Shirisha Paderu
Maybe you are looking for
-
When I click on pictures they will not enlarge
when I go to a website and there is a photo of an article for sale and I click on the picture to enlarge, the new window opens up blank
-
Call VB Script From ABAP Program
Hi, I need to call a VBS program from an abap program. This abap will run on both 4.6 and 4.0. I would be very grateful for any suggestions on how this can be done. Thanks and Kindest Regards Danielle
-
HOW MUCH IS IT TO GET MY SCREEN FIXED
I have a craked screen. How much is it to get it fixed?
-
When I click on IPhoto to open, all that happens is the little icon thing spins for hours. I can't see my album names, I can't see my pics or anything. Yet if I look in a file, I see that the albums are there. Also, it won't let me import new pics fr
-
IMac restarts when trying to boot up
Since about 2 weeks ago, my iMac has been having problems. The only problems which have occurred were during booting up. Whenever I try to boot up, there's a cycle - I press the back button, the chime plays, the grey screen, apple logo and loading w