Conditional Sum... dynamic Date range MDX
Hi
i had question just now and got the right answer for it. That was great. However, I ran and the result was not right.
It turned out I can not just sum up sales from the current date to the last date of sales but add one extra condition.
I have three dimensions: Invoice Date, Licence Start Date, Licence End date. I need to add a condition saying only sales with licence start date is equal or early than current licence end date for the below query.
I am looking at Filter function in MDX book right now. ahh It's been too long since I used the MDX last time. This is kinda urgent. Any help would be appreciated.
I have added the condition as follows. It is not right because I got the same result as the first one. It should be less.
And I think it's because the current member of licence start date for the expired month invoices are not applied right.
With member MEASURES.ActiveLicences as
sum (
Filter(
{[License Expiry Date].[FinancialYear].CurrentMember: null },
([Licence Start Date].[Financial_Year].CurrentMember <= [License Expiry Date].[FinancialYear].CurrentMember)
[Measures].[No of Students]
select {
MEASURES.ActiveLicences,
[Measures].[No of Students] } on columns,
[License Expiry Date].[FinancialYear].[YY-MMM].members on rows
from [Sales];
from
With member MEASURES.ActiveLicences as
sum (
{[License Expiry Date].[FinancialYear].CurrentMember: null },
[Measures].[No of Students]
select {
MEASURES.ActiveLicences,
[Measures].[No of Students] } on columns,
[License Expiry Date].[FinancialYear].[YY-MMM].members on rows
from [Sales];
Kind regards
Hi Sqlma,
According to your description, you are going to sum the measure for the members with the dondition that licence start date is equal or early than current licence end date for the below query, right?
In this case, you need filter out the members that licence start date is equal or early than current licence end date for the below query. And then sum the total measures using sum function. I have tested it on my local environment, here is a sample query
for you reference.
with set [aa]
as
filter
([Product].[Product Categories].members,
[Measures].[Internet Sales Amount]>30000)
member [measures].[b]
as
sum([aa],[Measures].[Internet Sales Amount])
select {[Measures].[Internet Sales Amount],[measures].[b]} on 0,
[aa] on 1
from [Adventure Works]
where [Date].[Calendar].[Calendar Year].&[2008]
Regards,
Charlie Liao
TechNet Community Support
Similar Messages
-
Scheduling WebI reports for Dynamic Date Ranges
Hello Everyone,
Our Env is BOBJ XI 3.1 SP2 FP2.5 integrated with SAP NW BW 7.02 EPH1
We are trying to schedule few WebI reports which can be used on ad-hoc basis as well. Some reports need to get data from starting of the month to today (like MTD) and few are with dynamic date ranges.
In case of relational universes i used to do Magic Date as mentioned here : http://www.dagira.com/2008/07/21/using-a-magic-date-value-in-prompts
But for OLAP Universes i have written a MDX filter prompt as :
<FILTER KEY= "@Select(Debit Memo Date\Debit Memo Date LOV)">
<CONDITION OPERATORCONDITION= "Between">
<CONSTANT CAPTION= "IIF (@Prompt('Enter\Select DM Start Date: ','D','First day of Current Month\First day of Current Month',mono,free,not_persistent,{'First Day of Month'},,User:0)='First Day of Month','First day of Current Month\First day of Current Month',@Prompt('Enter\Select DM Start Date: ','D','First day of Current Month\First day of Current Month',mono,free,not_persistent,{'First Day of Month'},,User:0))"/>
<CONSTANT CAPTION= "IIF (@Prompt('Enter\Select DM End Date: ','D','Date2\Today',mono,free,not_persistent,{'Today'},,User:0) > '1/1/2100 12:00:00 AM',''1/1/2010 12:00:00 AM'',(@Prompt('Enter\Select DM End Date: ','D','Date2\Today',mono,free,not_persistent,{'Today'},,User:0))"/>
</CONDITION>
</FILTER>
We are getting MDX erros because IIF can only return numeric values. So are there any other approaches for dynamically scheduling the reports or can the above MDX prompt be modified to make it work ?
- Vamsi ChIngo,
When we schedule the WEBI report we use the BEX query with a variable based on a customer Exit .
There are good examples in
https://wiki.sdn.sap.com/wiki/display/profile/Surendra+Reddy
In order to avoid providing a hard coded date restriction in the BEX query we want to have a flexible date range solution (e.g. data from 1.1.2011 until yesterday).
Is the folloing scenario possible:
Scheduled webi report with a hard coded date e.g. 1.1.1900 (for the BEX variable)
The BEX query should return the data from 1.1.2011 until yesterday (dynamically) if date = 1.1.1900
else it should return the data (for the e.g. adhoc reporting)
Is a customer exit like this possible ?
Pseudo code:
IF date = 1.1.900 then return sysdate-1 else return entered date
For a relational universe I always used a magic date condition -
I'm on ECC6.0, and looking to set up a dynamic date range in a variant.
The date range is a select-option on my selection screen.
I can easily setup the dynamic date for the 'low' value in the range,
but I can see no way to also declare a dynamic date in the 'high' value.
I also looked in TVARV maintenance and it doesn't seem possible there
either, as there's no way to declare variable values.
If I can't resolve this, I will have to change my program to include a
default high date and use that.
But even that may not work if we call the variant, which may overwrite
my default in the high value of the range with a blank value.
Does anyone know how to do this?
Thanks in advance for your help.Hi Jagan,
If you save the variant you can choose some options for the select-option. If you choose selection variabel type D (dynamic date calculation) you can choose out of several Names of Variables that provide for a LOW and HIGH value.
If you use type T, you can choose a variable that is stored in tabel TVARVC. You can add your own variable to table TVARVC using SE16.
Regards........
Chaitanya. -
How to put condition for one date range should not interfear with another ?
hi friends,
how to put condition for one date range should not interfear with another date range.
my data base table has two fields
from date
to date.
when we enter the date range in the data base , new date range means from date and to date should not interfear.
can anybody help me.
thanks &Regards,
Revanth
Edited by: rk.kolisetty on Jul 1, 2010 7:18 PMDo it the SAP way....
First entry...from is today, to is 99991231.
New dates entered, now we have two rows...:
from is original date to becomes yesterday.
From is today to is 99991231 -
Dynamic date range in the variant
Hi,
We have a background job that is scheduled to run on every 25th. One step of the job has a selection screen which has a Payment date range which is to have the dates 25th of previous to the 24th of the current month.
So every month this needs to be updated dynamically. For ex: If I look at the variant of the step of the job in period 04 the date should be "03/25/2010 to 04/24/2010". If I look in Period 05 then it should be "04/25/2010 to 04/25/2010".
Can anyone tell me if this can be achieved through a variant or does this have to be put in the code?
Regards,
raj/You can create a dynamic variant using STVARV following the steps in the given link...
http://wiki.sdn.sap.com/wiki/display/ABAP/Creatingdynamicvariantusingtable+TVARV
Now, the values in TVARVC need to be updated for each period. It can be done scheduling a separate BDC program, which runs for each period and updates the values. So, your date values will be changed for a new period by the background job and program variant wil pick up automatically the values from TVARVC. Check this link, which depicts a similar kind of requirement.
Re: Update TVARVC Table Dynamically
You can also calculate the values in intialization event each time the program runs as suggested by Sumit. But, if you need a variant then it won't help. The advantage with TVARVC is you can maintain different set of variants with different values. -
Dynamic date range creation for WebI query
Hi
I have a webi query where I need to provide a date range as selection. But the from date will be based on number of days that user will provide during query execution. For e.g. user will give no of days as 10 so the date range need to be created as (system date -10) to (system date).
I am not sure how to provide the option for user to input no of days and then calculate the date range.
Could you please help me here.
Regards,
AmitAmit.
it can be done but by creating multiple objects.
create Obj1: @prompt("Enter Number Of days",N,Mono,etc..) and capture the number of days in it.
Create your second object infact a filter object: Obj2: Sysdate
Third Object(filter) Obj3: (Sysdate-(@select(class\Obj1)))
give the between condition in webi using these two objects
between Obj2 and Obj3 -
Dynamic Date Range Filter - Rolling 15 Months
Hello All,
I'm having an issue with the below report filter:
Date.Date >= (TIMESTAMPADD(SQL_TSI_MONTH, 0, CURRENT_DATE)) AND Date.Date <= (TIMESTAMPADD(SQL_TSI_MONTH, 14, CURRENT_DATE))
The aim is for the above to return 15 months of data, today's date being 31/07/08 I would like all data to be returned from the 01/07/08 - 30/09/2009. The above filter however returns everything from the 31/07/2008 - 30/09/2008.
I have seen similar posts but never but have not come across a solution, any ideas?
Thanks
InnoveerOk.. Sorry guys, I found the post. For all who are interested:
Date.Date >= TIMESTAMPADD(SQL_TSI_MONTH, 0, TIMESTAMPADD(SQL_TSI_DAY, -(DAY(CURRENT_DATE)-1), CURRENT_DATE)) AND Date.Date <= TIMESTAMPADD(SQL_TSI_MONTH, 15, TIMESTAMPADD(SQL_TSI_DAY, -(DAY(CURRENT_DATE)), CURRENT_DATE)) -
Hi all,
I have 2 date fields in a page: Start Date, End Date. The Start Date should not be later than End Date.
I don't know how to write a validation to control TWO fields. I cannot use the built-in ADF declarative validation at Entity Level, since I want to set the autoSubmit=true to do validation at realtime.
What I have done is I created validator function for both fields, the function works fine except this:
1. user input 1-1-2000 to Start Date, user input 1-1-1999 to End Date. the invalid dialog appears for end date
2. user input 1-1-1990 to Start Date, but the End Date is still Invalid.
Is there anyway to fix this problem?
I am using Jdeveloper 11.1.1.2 with ADF BC.
Regards,
Samson FuI found the solution for this, post here for anybody have the same problem.
http://jdevadf.oracle.com/adf-richclient-demo/faces/feature/interfieldValidation.jspx
Regards,
Samson Fu -
Creation of Dynamic Date Variables to be used in WebI reports
What we are trying to achieve is to create 4 optional filters (Current Day, Current Week, Last Week, Last Month) on 4 different dates which will allow the users to use them in WebI reports.
When using an optional SAP Customer Exit variable in BEx and creating a Universe on top, the filter becomes mandatory (i.e. the whole Universe is filtered by the SAP Exit, irrespective of whether the filter is used in the WebI report). Even if the filter is flagged as optional at the Universe level, it still behaves as mandatory.
If each filter becomes mandatory then we'll have to create 16 different Universes (for each optional filter and date combination)! This is not feasible.
I've seen in other posts that MDX Statements are not currently supported for Universes base on BW and SAP Exit should be utilized.
So with the existing BO version, is it possible to create optional dynamic date variables or is that a product limitation?
We are on XI3.1 SP3 FP3.1
ThanksHi Adam,
In BEx, I would create this query very easily using the "Amount" key figure twice in my results and restricting each with a different SAP standard out-of-the-box delivered variable. For your reference, the variables in BEx are: 0FPER and 0FYTLFP.
If I expose these variables in my OLE DB for OLAP query, they are not transfered into the universe, but rather act as filters on the entire universe. I've seen in documentation that only "Ready for Input" variables can be transfered as options into the universe which is not something that I have seen mentioned in this thread.
>> In the BEx Query you have the option to either make the variable "ready for input" or not. The behavior is the same in Bex or in the Universe / Web Intelligence. "Ready for input" means the user can actually provide an input and without the flag the user can not provide an input. Yes those variables are supported in the Universe.
Why this is a problem: I can't create separate universes based on potential variable periods that users might want to see. Additionally, many financial reports require concurrent use of these measures in the same report. Also, in reality it's not 2 variables, but dozens.
>> Which is a decision you make already on the BEx query level. if you decide that the variable is not ready for input then the user can change the timeframe in BEx either.
Also, I don't have a good way to mimic the standard out-of-the-box functionality given with BEx in BO. If I custom create all my variables in the universe, how do I do a lookup from the system date to the fiscal calendar that is stored on the BW server? In other words, how does BO know which date belongs in which period? (the same would be true with factory calendars for a different functional area).
>> Variable are created in the BEx query and the Universe will leverage those.
If you want a dynamic date range then EXIT variable as part of the BEx query - ready for input or not - is the solution.
regards
Ingo Hilgefort
The only work around I can see is to require users to enter the current fiscal period and have the BO reports filter based off that user entered value. This is unfortunate as the entire purpose of SAP Exit variables is to avoid having to require user input at report time. -
SUMIFS with Date Range and Condition
Hi, I have search in the forums and read the online numbers guide but can't seem to get the formular working in Numbers.
I want to sum up a column of durations, if they are in between 2 dates and meet the condition to belong to one project. I have the following table:
project
total duration
project
start
end
duration
date range start
date range end
one
0
one
02.01.2013
02.01.2013
15:30
01.01.2013
31.01.2013
two
0
one
03.01.2013
03.01.2013
15:30
three
two
04.01.2013
04.01.2013
15:30
four
two
05.01.2013
05.01.2013
15:30
five
three
06.01.2013
06.01.2013
15:30
six
three
07.01.2013
07.01.2013
15:30
seven
three
08.01.2013
08.01.2013
15:30
I have the following formular but it does not give me any value: =SUMIFS(F,C,A5,D"≥"$G$2,E"≤"$H$2)
What am I doing wrong
Thank you for your help.Hi Barry,
thank you very much for your detailed reply.
The first difference I spot is that my duration is in hours:minutes 00:00 but this should not make a difference, right? I attach you here some sample data:
Project
Start date
Start time
End date
End time
Duration
Project 1
07.01.2013
11:00
07.01.2013
11:42
00:42
PINC: 1
07.01.2013
16:11
07.01.2013
17:11
01:00
Theatro
07.01.2013
19:50
07.01.2013
19:54
00:03
Project 3
08.01.2013
11:19
08.01.2013
13:30
02:11
Project 1
09.01.2013
12:32
09.01.2013
13:02
00:30
PINC: 1
09.01.2013
17:55
09.01.2013
18:29
00:34
Project 3
09.01.2013
18:29
09.01.2013
19:36
01:06
And I will go through my formular again and check if everything is correct.
Many greets, Andreas -
Hi All
I need some advice on the below, it works, gives the answers I want, but I believe the filter on the set can be moved to a where clause, and the MTD can work effectively then with the sum of the date range on the [RangeHasResponse] measure (advice apart
from "if it ain't broke don't fix it" ;) ). This is query for a report where I can sub in a param date range (set the Today value, and the from in the DateRange), and produce the Sum of Has Response across that date range, and also the MTD
for last month up to the ToDate.
Any advice on how the MDX could be better structured would be great, I can understand I'm calculating members, then adding them to my query, it just seems I should be calculating them in the SELECT based on a filter. Output just needs to be
[MTD]: single sum of Has Response to the current todate for that month
[RangeHasResponse]:Sum of the entire range
[Has Response] : sum on the last day, this isn't necessary, I'm just curious to see how that would tie into a filter, if it ruins the above leave it out.
WITH
SET [ToDate]=[Date].[Year - Quarter - Month - Date].[Date].&[2014-02-22T00:00:00]
SET [DateRange] =
[Date].[Year - Quarter - Month - Date].[Date].&[2014-01-01T00:00:00]:
[ToDate].item(0)
MEMBER [Measures].[MTD] AS
SUM(MTD([Date].[Year - Quarter - Month - Date].CurrentMember),[Measures].[Has Response])
MEMBER [Measures].[RangeHasResponse] AS
SUM([DateRange],[Measures].[Has Response])
SELECT
{[Measures].[MTD],[Measures].[Has Response],[Measures].[RangeHasResponse] } on columns
,[ToDate] on rows
FROM
[ISD Prototype]
Thanks
Best Wishes, The Redman; If something helps, please help show it by voting, if it solves, bonus!Hi GGoldspink,
In MDX, the CREATE MEMBER statement defines calculated members that are available throughout the session, and therefore, can be used in multiple queries during the session. So if the members can will be used in multiple times in SELECT clause, we can create
a calculated member, and then use this members on SELECT clause which will improve the query performance.
In your scenario, are there any performance issue in your MDX query? In this case, I'd suggest you enable SQL Sever profiler to monitor the queries, and check which part in the query took a very long time to run. Here is a useful link for your reference.
http://sqlmag.com/database-performance-tuning/using-sql-profiler-tune-mdx-queries
Besides, here is a document which will help you understand where issues can occur in your existing MDX code that will prevent you from experiencing the performance improvements, and provide advice on how to avoid these issues in your new MDX coding.
http://technet.microsoft.com/en-us/library/bb934106(v=sql.105).aspx
Regards,
Charlie Liao
If you have any feedback on our support, please click
here
Charlie Liao
TechNet Community Support -
Creation of internal table dynamically based on the Date Range entered
Hi SAPgurus,
I have been facing one issue i.e creation of internal table dynamically based on the date range entered in the selection screen. For example the date range I am giving as 06/2006 to 08/2006, it should display the Fieldcatelog dynamically, this part i have completed but the only issue I am facing is to populate the sales data into that fields.
Right now my program is displaying the ALV like this.
Ex:
<b>CSR District 06/2006 07/2006 08/2006 totals</b>
Shiva New York 10.00
Shiva new york 30.00
Shiva new york 40.00
but it should display like this
<b>CSR District 06/2006 07/2006 08/2006 totals</b>
Shiva New York 10.00 30.00 40.00
80.00
Please help me in this scenario, how to acheive like this..
Thanks & Regards,
Sivaram KandulaHi Sivaram,
I also got the same requirement . i saw rich and your code whatever you have uploaded.i have created dynamic internal table but i am facing the issue to populating the data to my dynamic internal table.
Sivaram, can you please explain your code after this.
*<dyn_table>
*tab_item.
LOOP AT tab_item.
ASSIGN COMPONENT 1 OF STRUCTURE <dyn_wa> TO <dyn_table>.
ASSIGN COMPONENT 2 OF STRUCTURE <dyn_wa> TO <dyn_table>.
* <dyn_wa> = tab_item-bztxt.
* <dyn_wa> = tab_item-total.
* APPEND <dyn_wa> TO <dyn_table>.
** <dyn_wa> = tab_item-total.
** ASSIGN tab_item-bezei TO <dyn_wa>.
* APPEND <dyn_table>.
ENDLOOP.
how you are puting the loop at tab_item. but tab_item is already commented.
can you send me the code after that.
i am sending some part of my code.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = gt_fCAT1
IMPORTING
ep_table = new_table.
ASSIGN new_table->* TO <dyn_table>.
create data new_line like line of <dyn_table>.
assign new_line->* to <dyn_wa>.
select vbeln
fkart
vkorg
vtweg
fkdat
spart
fksto
from vbrk
client specified
into table gt_vbrk
where mandt = sy-mandt
and fkart in ('ZF5','ZFR')
and vkorg = '1100'
and vtweg = '20'
and fkdat in s_fkdat
and spart = '06'
and fksto = ' '.
if gt_vbrk[] is not initial.
select vbeln
fkimg
prsdt
netwr
matnr
arktx
werks
mwsbp
from vbrp
client specified
into table gt_vbrp
for all entries in gt_vbrk
where vbeln = gt_vbrk-vbeln
and werks in s_werks
and matnr in s_matnr.
endif.
select mnr ltx spras from t247
into table it_t247
where spras = 'E'.
data: lv_month1 type vbrp-prsdt,
name1(3) type c,
s_month type string,
s_month1 type string,
s_month2 type string.
* lv_netwr1 type vbrp-netwr,
* lv_mwsbp1 type vbrp-mwsbp.
loop at gt_vbrp into gs_vbrp.
gs_final2-matnr = gs_vbrp-matnr.
gs_final2-arktx = gs_vbrp-arktx.
gs_final2-fkimg = gs_vbrp-fkimg.
lv_month1 = gs_vbrp-prsdt.
read table it_t247 into wa_t247 with key mnr = lv_month1+4(2).
if sy-subrc eq 0.
name1 = wa_t247-ltx.
endif.
concatenate name1
lv_month1(4) into s_month SEPARATED BY '_' .
CONCATENATE S_MONTH 'QTY' INTO S_MONTH1 SEPARATED BY ''.
CONCATENATE S_MONTH 'VALUE' INTO S_MONTH2 SEPARATED BY ''.
gs_final2-month = s_month.
lv_netwr1 = gs_vbrp-netwr.
lv_mwsbp1 = gs_vbrp-mwsbp.
gs_final2-MONTH_QTY = S_MONTH1.
GS_FINAL2-MONTH_VAL = S_MONTH2.
gs_final2-value = lv_netwr1 + lv_mwsbp1.
append gs_final2 to gt_final2.
clear: gs_final2. "lv_name2.
endloop.
if gt_final2[] is not initial.
sort gt_final2 by matnr month ascending .
loop at gt_final2 into gs_final2.
gs_final2_01 = gs_final2.
collect gs_final2_01 into gt_final2_01.
endloop.
endif.
ENDIF..
Regards
Ankur -
Displaying different sums in the same row based on date ranges
Say I had a table like this
DECLARE @t1 TABLE (RowId INT PRIMARY KEY IDENTITY(1,1), BusinessType VARCHAR(100), SalesPerson VARCHAR(100), Category VARCHAR(100), OrderAmount DECIMAL(10,2), OrderDate DATETIME )
Now I want to get a result that is grouped first by BusinessType, then SalesPerson and include derived columns that are sums based on different date ranges.
Month-to-date = from the start of the current month to today
Month-to-date previous year = from the start of the current month to today 1 year ago
DECLARE @today DATETIME
DECLARE @today_prev_year DATETIME
DECLARE @year_start DATETIME
DECLARE @year_prev_start DATETIME
DECLARE @month_start DATETIME
DECLARE @month_prev_start DATETIME
SET @today = GETDATE();
SET @today_prev_year = DATEADD(YEAR,-1,@today)
SET @year_start = CAST('01/01/' + CAST(DATEPART(YEAR,GETDATE()) AS VARCHAR(10)) AS DATETIME);
SET @year_prev_start = DATEADD(YEAR,-1,@year_start)
SET @month_start = DATEADD(month, DATEDIFF(month, 0, @today), 0); --gets the first of the current month
SET @month_prev_start = DATEADD(YEAR,-1,@month_start); --gets the first of the current month
SELECT t.BusinessType,t.SalesPerson,t.Category
SUM(CASE WHEN o.OrderDate > @month_start AND ac.DocumentDate < @today THEN o.OrderAmount ELSE 0 END) AS MTDActualAmount
SUM(CASE WHEN o.OrderDate > @month_prev_start AND ac.DocumentDate < @today_prev_year THEN o.OrderAmount ELSE 0 END) AS MTDPrevActualAmount
FROM @t1 t
Hope this is clear as to what Im trying to do. Im ultimately going to pull this into an SSRS report, so im wondering if I can do this different SUM values in the report and handle the grouping there.
Thoughts?Based on your example (with a group by added) it should work.
However, if you incorperated a calendar table (http://social.technet.microsoft.com/wiki/contents/articles/29260.tsql-calendar-functions-and-tables.aspx)
you could lose all those manually set parameters:
DECLARE @t1 TABLE (RowId INT PRIMARY KEY IDENTITY(1,1), BusinessType VARCHAR(100), SalesPerson VARCHAR(100), Category VARCHAR(100), OrderAmount DECIMAL(10,2), OrderDate DATETIME, DocumentDate DATETIME)
INSERT INTO @t1 (BusinessType, SalesPerson, Category, OrderAmount, OrderDate, DocumentDate) VALUES
('A','Joe','CatA',10,'2015-01-01','2015-01-01'),('A','Joe','CatB',10,'2015-01-02','2015-01-01'),('A','Joe','CatA',30,'2015-01-03','2015-01-04'),('A','Joe','CatB',40,'2015-01-04','2015-01-01'),('A','Joe','CatA',100,'2015-02-01','2015-02-01'),
('A','Joe','CatB',100,'2015-02-02','2015-02-01'),('A','Joe','CatA',300,'2015-02-03','2015-02-04'),('A','Joe','CatB',400,'2015-02-04','2015-02-01'),('A','Bob','CatA',1,'2015-01-01','2015-01-01'),('A','Bob','CatB',1,'2015-01-02','2015-01-01'),
('A','Bob','CatA',3,'2015-01-03','2015-01-04'),('A','Bob','CatB',4,'2015-01-04','2015-01-01'),('A','Bob','CatA',10,'2015-02-01','2015-02-01'),('A','Bob','CatB',10,'2015-02-02','2015-02-01'),('A','Bob','CatA',30,'2015-02-03','2015-02-04'),
('A','Bob','CatB',40,'2015-02-04','2015-02-01'),('B','Joe','CatA',10,'2015-01-01','2015-01-01'),('B','Joe','CatB',10,'2015-01-02','2015-01-01'),('B','Joe','CatB',40,'2015-01-04','2015-01-01'),
('B','Joe','CatA',100,'2015-02-01','2015-02-01'),('B','Joe','CatB',100,'2015-02-02','2015-02-01'),('B','Joe','CatA',300,'2015-02-03','2015-02-04')
SELECT t.BusinessType,t.SalesPerson,t.Category,
SUM(CASE WHEN OrderDate >= monthStart AND DocumentDate < today THEN OrderAmount ELSE 0 END) AS MTDActualAmount,
SUM(CASE WHEN OrderDate BETWEEN prevMonthStart AND prevMonthENd AND DocumentDate >= yearStart THEN OrderAmount ELSE 0 END) AS MTDPrevActualAmount
FROM @t1 t
INNER JOIN calendar c
ON today = CAST(CURRENT_TIMESTAMP AS DATE)
Group by t.BusinessType,t.SalesPerson,t.Category -
Sum an amount between a certain date range
Hello,
I am working out a home budget and want to know how to calculate what is due this month.
I have two columns - "Amount" and "Due Date". Some content for an example is:
Amount,Due Date
20,15/05/2009
300,16/05/2009
40,1/06/2009
What I want is a formula which will sum the total amount of items due within this months' date range. If the date range could be as automatic as "This Month" that would be great otherwise I would say IF "Due Date" between 1/05/2009 and 31/5/2009.
Is this possible?In column D, the formula is:
=YEAR(C)*100+MONTH(C)
In B8 and in B9 the formula is:
=SUMIF(D,YEAR(A)*100+MONTH(A),B)
Yvan KOENIG (from FRANCE jeudi 14 mai 2009 15:30:56) -
Dynamic Variant for Date Range
Making the Variant for Date or Date Range Dynamic in the Selection Screen of any Program.
There are actually many ways you can make the Variant for Dateu2019s Dynamic.
1. Providing he Values in the Variant Variables.
2. By creating the variables in the table TVARVC
3. By Initializing the values in the program itself.
I saw many posts with respect to these and found that everyone has their own way of dealing. Even I wrote code in the program initialization to get this done.
Here in this post I am showing you the easiest option which is available in the Variant creation.
EX : If you want to execute the batch job based on a date range.
SY-DATE u2013 60 days , that means always your program should execute the batch job based on System Date. And the variant should change accordingly.
Following are the step by stop to do that.
1. Select your program and select the Variant Radio button and then Click on Display.
2. It will pop up a screen with variant option below the program name.
3. Enter the Variant name and click on Create
4. You will see a screen, with the Attributes button.
5. Once you click on the Attributes button, it will take you a screen with selection option.
6. In my scenario my input is based on Calender Day, so select the Selection Variable for Calender Day: You will find 2 options T & D.
7. Select D: Dynamic date Calculation, then select the Name of Variable (input using f4). You can find many options.
8. Scroll down the Variant Attributes and select current date u2013 xxx, current date + yyy
9.Though it seems to be inactive, just double click on the row to provide the date range.
10. Just enter the value for xxx and yyy to get you dynamic range based on number of days
11. In my scenario I have to consider System Date u2013 60 days. 0 means current day.
12. Click on OK to check the range has been reflected or not. Then save the Variant and check the value by executing the program with saved Variant.
You can check the same in blog with all the screen shots attached but this thing is so easy you don't require screen shots.
Regards
Shankar ChintadaHi Shankar,
It would be great if you can put this information in Wiki .
Pravender
Maybe you are looking for
-
Drop Down Menu going up in IE 8- HELP!
I'm new to using the spry widgets in CS3 Dreamweaver, and I'm trying to create my first horizontal menu where one of the items will have a drop down menu. It works in all browsers except for IE8, where it starts at the top of the page and goes down.
-
Satellite L875D-S7230 Sound problems / drivers won't install
I've run a PC tech support service for over 10 years so I've tried all the standard fixes to no avail. Main problem was after I started using my laptop with an HDMI cable to a projector -- the audio and video worked fine via HDMI, but when I disconne
-
HT4436 Can I create a second email account?
How do I create a second iCloud email account?
-
Wild card pattern selection '+' compatibilty with BWA
Hello BWA experts, We have a situation in our production system where, when we enter a wild card string character in the variable selection like for example 1++6* the report does not return any result. The same when run with 16 output is obtained. Th
-
Method of Physical Inventory.....
Can anybody suggest me how many types of Methods are available for Physical Inventory in MM. Pls also provide the brief description with process steps. And also pls explain me What is ABC Analysis ?