How to calculate a cumulative total in HANA
Hello,
I have a detail table (e.g. GL line item table) which has entries for 'posting date', account number, year, month, posting amount (single key figure) and account type (whether the account is a profit & loss account or a balance sheet account.
The requirement is to create a view which shows balance of month for profit and loss accounts and cumulative balance per month for balance sheet accounts (i.e. total of all line items till end of the month, not just for the month).
Currently I am able to get only balance for the month , but not the cumulative balance.
How can I calculate a cumulative amount column/key figure - either through Analytical view or calculation view?
Thanks,
Ninad
The Window Functions should help. Here is a sample query in SPS06 using a sum over function against an SAP HANA Live standard view.
SELECT Year("BillingDocumentDate_E") as "Invoice_Year", "BillingDocumentDate_E" as "Invoice_Date", round("TotalNetAmount_E") as "Billed_Amount",
round(Sum("TotalNetAmount_E") OVER (partition by Year("BillingDocumentDate_E") order by "BillingDocumentDate_E")) as "YTD_Amount"
FROM "_SYS_BIC"."sap.hba.ecc/BillingDocumentQuery"
WHERE "SAPClient" = '004' and "SoldToPartyName" = 'Becker Berlin' and "BillingDocumentDate_E" >= '2002-01-01'
GROUP BY Year("BillingDocumentDate_E"), "BillingDocumentDate_E", "TotalNetAmount_E"
ORDER BY 1, 2
Message was edited by: Marc Daniau
Similar Messages
-
How to calculate the cumulative sum with certain interval in SAP HANA
Hi Experts,
I have a scenario in which I have a column with Boolean values and need to calculate the cumulative values in the interval where there are consecutive ones as mentioned below,
ID Date column 1
1 9-14-2014 14:22:00 1
1 9-14-2014 14:25:00 1
2 9-14-2014 13:22:00 0
1 9-14-2014 15:02:00 0
1 9-14-2014 14:37:00 0
2 9-14-2014 14:25:00 1
2 9-14-2014 14:32:00 1
1 9-14-2014 14:05:00 1
2 9-14-2014 14:45:00 0
2 9-14-2014 14:59:00 0
1 9-14-2014 15:12:00 1
1 9-14-2014 15:18:00 1
1 9-14-2014 15:21:00 1
First needs to group by 'ID' and Order By ' Date' and calculate the calculated column 'cumulative sum' for the consecutive ones in 'column1' as
ID Date column 1 Cumulative sum
1 9-14-2014 14:05:00 1 1
1 9-14-2014 14:22:00 1 2
1 9-14-2014 14:25:00 1 3
1 9-14-2014 14:37:00 0 0
1 9-14-2014 15:02:00 0 0
1 9-14-2014 15:12:00 1 1
1 9-14-2014 15:18:00 1 2
1 9-14-2014 15:21:00 1 3
2 9-14-2014 13:22:00 0 0
2 9-14-2014 14:25:00 1 1
2 9-14-2014 14:32:00 1 2
2 9-14-2014 14:45:00 0 0
2 9-14-2014 14:59:00 0 0
Is there any function and way to calculate this without loops in procedure?
Please help!!. Thank you!!
-GayathriHi Henrique,
The SQL,
SELECT id, date, col1, sum(col1) over (partition by col1 order by id, date) as cumulative_sum
will give me the cumulative value for all the col 1 with same value which is not my requirement,
the above will give the result as shown below. I have also added the correct values as per my requirement as well
ID Date column 1 Cumulative sum correct ***_sum
1 9-14-2014 14:05:00 1 1 1
1 9-14-2014 14:22:00 1 2 2
1 9-14-2014 14:25:00 1 2 3
1 9-14-2014 14:37:00 0 0 0
1 9-14-2014 15:02:00 0 0 0
1 9-14-2014 15:12:00 1 4 1
1 9-14-2014 15:18:00 1 5 2
1 9-14-2014 15:21:00 1 6 3
2 9-14-2014 13:22:00 0 0 0
2 9-14-2014 14:25:00 1 1 1
2 9-14-2014 14:32:00 1 2 2
for my requirement , I need to find the cumulative value only for the consecutive 1s if there are 0s in between then there should be a break and cumulative sum should start again for the next set of consecutive 1s
Hope you could help. Thanks.
-Gayathri -
How to calculate % based on totals of a characteristic
HI BI query goeroes,
I have following query:
Sales org - S&OP - Channel - PSI - KeyFigure1 - % S&OPKF1 - % Channel KF1
S100--SAA---1010/60--
10/30
S100--SAB---2020/60--
20/30
total ChannelA--
30
S100--SBA---1515/60--
15/30
S100--SBB---1515/60--
15/30
total ChannelA--
30
total S&OP S 60
Question is how to calculate the last two colums.
First colum should calculate the Keyfigure1 percentage based on the overall total of S&OP per salesorg (keep in mind that we have multiple sales orgs).
Last colum should calculate the Keyfigure1 percentage based on the total of Channel per salesorg/s&op group.
Can anyone please assist me how to do this?
I am using the BI7.0 query designer.Hi,
To Calculate % Channel KF1 you can use 'Percentage of Result'(KeyFigure1).
To calculate % S&OPKF1 you can use ' Pecentage of Overall Result' (Keyfigure1).
These are functions are available in the Percentage Functions when you create a formula or a CKF.
Hope this helps. -
How to calculate the Page total in Excel format
Hai all,
How can we calculate the page total in Excel format, directly in RTF without using the summary column in the RDF.
Regards<?add-page-total:TotalFieldName;’element’?>
where
TotalFieldName is the name you assign to your total (to reference later) and
’element’ is the XML element field to be totaled.
You can add this syntax to as many fields as you want to total.
Then when you want to display the total field, enter the following syntax:
<?show-page-total:TotalFieldName;’Oracle-number-format’?>
Pls refer XML Publisher user guide for more info on this.
Kiran -
How to calculate forign currency total amount in sale order???
how to convert forign currency total amount in indian rupees on sale order pld ???
Edited by: VINAYAK CHA on Feb 21, 2012 1:30 PMDea Srujal
SELECT T0.[Docdate],T1.[ItemCode],T1.[U_jobno]As 'Job Card No',T1.[Quantity],T0.[CardCode],T2.[U_SP],T2.[U_MA],T2.[U_ID], T2.[U_OD],T2.[U_testfield],T0.[Docduedate]
FROM ORDR T0 INNER JOIN RDR1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode INNER JOIN OHEM T3 ON T0.OwnerCode = T3.empID
WHERE T1.[U_INRPRICE]>='35,000' And (T0.[Docdate]>='[%0]' and T0.[Docdate]<='[%1]' )and T1.[ItemCode]!='SEAL' AND T0.[DocStatus]='O'
iam using above query with above formatted search as i post in previous answer.
but still some item is missing in query
kindly do the needful -
How to calculate subtol and total values in alv.
Hi expert,
I want to calculate the subtol and total values in alv as follows,
example:
month: Jan Fer Mar Apr
-50 -30 40 -10
-20 -13 -12 -10
subtotal -70 -43 28 -20
-10 -10 -10 -10
-10 -31 -15 -10
subtotal -20 -41 -25 -20
total -90 -84 3 -40
when i put '-' in front of the month,i define the month type c,
and when the type is c,it cann't calculate the subtotals and totals.
how can i do can make the layout like the example.
thanks...
Edited by: Heum Kim on Aug 25, 2008 3:54 AMThe below code is not generic one. I am just looking for generic one. You try to fix it using the similiar approach.
REPORT ZTEST_ALV_DEC.
data: fcat type lvc_s_fcat,
tfcat type lvc_t_fcat.
data: begin of itab occurs 0,
carrid(10),
quan type DEC_16_02_S,
end of itab.
itab-carrid = 'AA'.
itab-quan = '-10000.00'.
append itab.
fcat-fieldname = 'QUAN'.
fcat-tabname = 'ITAB'.
fcat-decimals_o = 2.
fcat-edit_mask = 'V__,___.__'. "This is not generic
append fcat to tfcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
I_CALLBACK_PROGRAM = sy-repid
IT_FIELDCAT_LVC = tfcat
TABLES
t_outtab = itab
EXCEPTIONS
PROGRAM_ERROR = 1 -
How to Calculate Line items Total of Matrix Column
hai experts,
Im facing a problem like
1. i have a matrix with a column Labour Costs in that im taking some cost.
2. in footer a have a Edit Text like Total Labour Cost
3 when i enter amount in matrix column it sholud disply that value in total labour cost and when we add new row ,labour cost it should add to 'total labour cost' in footer.Like Invoice Documents.Where do you want to implement this like sapscript / smartforms or adobe forms? please specify.
-
How to calculate the Grand total
Hi all,
I have a table that has three column as Instrument_Name, Instrument_Currency , Value.
I am using the "table view" to show the data on dashboard.The table shows instrument name , its currency and a value(in that currency).
Could it be possible that while displaying the grand total of "Value", i should convert the value in a single base currency as USD.
ThanksHi,
Well you can and should create a total on the calculation of the Margin%
But you have to define the calculation correctly, for example if you will use in the calculation the fields without aggregation
you will get wrong output but if you'll define the calculation as something like:
CASE WHEN ( SUM(Revenue)+SUM(Cost)) = 0 THEN 0 ELSE SUM(Margin)/( SUM(Revenue)+SUM(Cost)) END
and then create a total with SUM Aggregation I think you'll get what you asked for -
How to calculate total for field for particular day. in smart forms
hi,
pls help in this problem,
how to calculate cumulative totals for the particular field in samrtformsHi ,
Either you can calculate the sum in driver program with
Loop at where Condition .
Sum the required field .
endloop .
Then pass it to smartforms
Or
Double Click on table node .
In the conditions tab give the required condition .
select calculation tab.
In operation select Total , in field name give the name of the field you want to sum
and in targer field name specify the name of the field that should contain the result .
To convert the total in to words use the function module in program lines
CALL FUNCTION 'HR_IN_CHG_INR_WRDS'
EXPORTING
amt_in_num = w_total
IMPORTING
AMT_IN_WORDS = w_total_words
EXCEPTIONS
DATA_TYPE_MISMATCH = 1
OTHERS = 2
Regards -
How to calculate totals in Blocked ALV Report
Hi All,
Can any body tell how to calculate totals & sub totals in
Blocked ALV Report[Blocked List].
Thanks in advance
Thanks & Regards,
Rayeezuddin.read this it might help
Sums
15. No_sumchoice(1) TYPE c : This parameter allows the choice for summing up
Only by fieldcatalog.
Value set: SPACE, 'X'
'X' = fields which are to be summed, passed by the calling program (FIELDCAT-DO_SUM = 'X'). The user should not be able to change this value interactively.
16. No_totalline(1) TYPE c : Removes the option of having totals after sub-totals.
Value set: SPACE, 'X'
'X' = no total record is to be output. Subtotals can still be calculated and output. The fields in the subtotals are flagged DO_SUM = 'X' in the field list.
17. No_subchoice(1) TYPE c : Does not allow the user to interactively change the field chosen for subtotals.
Value set: SPACE, 'X'
'X' = value whose change triggers subtotals, provided by the calling program. The user should not be able to change this value interactively.
18. No_subtotals(1) TYPE c : No subtotals possible
Value set: SPACE, 'X'
'X' = no subtotals.
19. Numc_sum(1) TYPE c : Totals only possible for NUMC-Fields.
20. No_unit_splitting TYPE c: No separate total lines by inh.units
21.totals_before_items TYPE c: Display totals before the items
22. Totals_only(1) TYPE c : Show only totals
Value set: SPACE, 'X'
'X' = only total records are output.
23. Totals_text(60) TYPE c : Text for 1st col. in totals
Value set: SPACE, string (max.60)
' ' = The first column in the total record contains an appropriate number of '*'s to indicate the total by default. If the first column is wide enough, the string 'Total' is output after the asterisks.
'String = The string passed is output after the total indicated by '*', if the column is wide enough.
24. Subtotals_text(60) TYPE c : Texts for subtotals
Value set: SPACE, string (max.60)
' ' = In the first column of subtotal records, the subtotal is indicated by an appropriate number of '*' by default. If the first column is not a subtotal criterion, the string 'Total' is output after the asterisks, if the column is wide enough.
'String = the string passed is output after the subtotal indicated by '*', if the column is wide enough and the first column is not a subtotal criterion. If it is a subtotal criterion, its value is repeated after the total, if the column is wide enough.
ELSE TELL ME I WILL PASTE COMPLETE HELP
regards -
How to calculate total number of pages in a script
hi
how to calculate total number of pages in a scriptJyothsna,
Date:-&sy-datum&
Time:-&sy-timlo&
Total No.of Pages:-&sapscript-formpages&
Page No:-&PAGE&/&SAPSCRIPT-FORMPAGES&
Give the above said lines in your text editor,and given the paragraph format.Better create one more window and give the above said lines in the text editor.
K.Kiran. -
Hi frinds ,how to calculate the totals in smartforms
1)how to calculate the totals in smartforms .
Hi,
To calculate totals and sub totals in sap scripts you can use subroutines.
Say if you have to add the unit price (KOMVD-KBERT) then in the main window whereever tat value is picked write this routine
/: DEFINE &TOT_PRICE&
/: PERFORM F_GET_PRICE IN PROGRAM /:USING &KOMVD-KBERT& /:CHANGING &TOT_PRICE& /:ENDPERFORM
Then write the variable where ever you want it to be printed (mostly it will be in footer window)
Then create subroutine pool program and you have to write the code.
FORM F_GET_PRICE tables int_cond structure itcsy
outt_cond structure itcsy. data : value type kbert.
statics value1 type kbert.
Read int_cond table index 1.
value = int_cond-value.
value1 = value1 + value.
Read outt_cond table index 1.
outt_cond-value = value1.
Modify outt_cond index 1.
ENDFORM.
regards.. -
Urgent : how to calculate sub total and grand total in smart forms
Hi Friens..how to calculate sub total and grand total in smart forms..How to print them in smart forms...Also kindly explain how to handle events in smart forms..Thanks in advance
Re: Subtotal with Table Node in smartforms
-
How to calculate total no of days in List column
Hi,
I've start date and end date. Can you please help me how to calculate total number of days.
Column Name = Leave Start Date (05/02/2015)
Column Name = Leave End Date (19/02/2015)
Column Name = Total Days (This is calculated column)
I used below formula but its showing only 14 days however it should show 15 days
=DATEDIF([Start Date], [End Date],"d")
Thanks,I got the answer
Formula is
=DATEDIF([Start Date], [End Date]+1,"d")
Thanks.:) -
How to calculate the difference of two totals which are of the same group?
Post Author: mingli
CA Forum: Formula
Hello,
I have an existing report which has a group defined. The group generates two set of data, at the footer of each set of data, the total is calcuated. Now I need to calculate the difference between the totals. For example:
value
set 1
item 1 100
item 2 200
item 3 300
set 1 total 600
set 2
item 1 200
item 2 20
item 3 300
item 4 40
set 2 total 560
difference 40
My question is: how can I do this? I'm thinking about create a formula. But the problem is, these two totals have the same field name. Could someone help me out?
Thanks.Post Author: deejayw
CA Forum: Formula
Hi,I have a similar type of query...my Sets only ever contain two entries but there is an unknown number of sets. value
set 1
item 1 100
item 2 200
difference (item2 - item1) = 100
set 2
item 1 200
item 2 20difference (item2 - item1) = -180
Set 3, Set 4, etc, etc I need to figure out how to calculate the "difference (item2 - item1)" total above. I am really confused by this and need assistance. Many thanks.
Maybe you are looking for
-
APPCRASH on Windows 7 no matter what I do
I am running Windows 7 home premium, 64 bit. I have tried every fix that I could possibly find on the internet to fix my Skype. I have reinstalled it countless times, deleted Appdata files, upgraded it, tried to install older versions, tried to clean
-
Installation CD lost: Advice nee
I own a Audigy soundcard, my hard dri've failed and I am rebuilding my system. But I have lost my original cd's and the download area dosen't seem to have all the orginal drivers, etc. What can I do?
-
Hi, We need to install Cubes from the BI Content.If we choose the Grouping option 'In data flow before', then all the objects required for activating the Cube are collected. These objects include Update Rules, Infosource etc. Right? My questions are:
-
MyRIO upgrade to Ni-myRIO13.1 may require chrome browser reset
I upgraded the myRIO to the newest drivers myRIO13.1 and afterwards connecting to the web server was partially broken. Most sections worked, but the buttons for: Security Administration Web services management Web Server configurations ... were no lo
-
Is it true that Camera Raw 7.1 and higher versions are only compatible with CC, not with CS 5?