Set variable date in a procedure with current month and previous month
Hi guys, I need to set two date range in one procedure. The date should be
@datefrom the third day of the current month
@dateto the seventh day of the current month
@datefrom-1 the third day of the previous month
@dateto-1 the seventh day of the previous month
format like @datefrom '2014-03-03' @dateto '2014-03-07'
@datefrom '2014-02-03' @dateto '2014-02-07'
The problem for me it's going to be the jump between the years...2014 to 2015...any advice?
Thanks
DECLARE @FirstDayOfCurrentMonth DATE
SELECT @FirstDayOfCurrentMonth = DATEADD(MONTH, DATEDIFF(MONTH, '01/01/1900', Current_timeStamp), '01/01/1900')
SELECT
DATEADD(DAY, 2, @FirstDayOfCurrentMonth) As ThirdDayOfCurrentMonth
,DATEADD(DAY, 6, @FirstDayOfCurrentMonth) As SeventhDayOfCurrentMonth
,DATEADD(DAY, 2, DATEADD(MONTH, -1, @FirstDayOfCurrentMonth)) As ThirdDayOfPreviousMonth
,DATEADD(DAY, 6, DATEADD(MONTH, -1, @FirstDayOfCurrentMonth)) As SeventhDayOfPreviousMonth
OUTPUT
ThirdDayOfCurrentMonth SeventhDayOfCurrentMonth ThirdDayOfPreviousMonth SeventhDayOfPreviousMonth
2014-12-03 2014-12-07 2014-11-03 2014-11-07
Best Wishes, Arbi; Please vote if you find this posting was helpful or Mark it as answered.
Similar Messages
-
Parameter for Current Month and Previous Month
I'm trying to create a parameter for current month and previous month based on the ex_date, but not sure what i'm doing wrong.
where ex_date = @SelectDate
I created a second dataset below for the values in the parameters.
SELECT Month(CURRENT_TIMESTAMP) AS 'Month', 'Current Month' as 'Current Month'
union all
SELECT Month(CURRENT_TIMESTAMP)-1 AS Month, 'Previous Month' as 'Previous Month'
Results
Month Current Month
3 Current Month
2 Previous Month
Once I preview it I get "Conversion failed when converting date and/ or time from character string" I changed the data type to "date/Time" but that did not make a difference. The date is convert (varchar(10), ex_date, 101) so looks like
11/12/2014.
I've also tried expressions like =month(now()) to pull current month with same error so i'm not sure what i'm doing wrong. Any ideas?i tired this real simple report
in the first dataset - my main report query - select name from sysdatabases where month(crdate())=@month
in the second dataset - select month(getdate()) as Month1
in the parameters - choose int data type and available values - select the second data set
in the first data set- add this parameter..( i am assumming you know this, since you have done)
in the preview you should get the drop down with current month number - 3
and if you run the report, it will display the database names that were created in march. remember we are no checking year, so will get all that were created in march across the years.
Hope it Helps!!
I'm looking to have the dropdown say "Previous Month" and "Current Month" as a option. I know how to get the information in SQL, but not sure how this translates or put into a parameter.
Current Month
list_date BETWEEN
DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0)
AND
DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) + 1, 0)
Previous Month
list_date between
CONVERT(varchar,dateadd(d,-(day(dateadd(m,-1,getdate()-2))),dateadd(m,-1,getdate()-1)),106) /* Last Month */
and
CONVERT(varchar,dateadd(d,-(day(getdate())),getdate()),106) -
Current month and previous months of fiscal year period data
Hi All,
My requirement is end user will enter month ie (fiscal year period ) and in report my requiremnt is to show data in two columns 1.Current month data and
2.April till date.
Please let me know how to do this and please send the coding to be done in CMOS.
RegardsHi,
In your query, you should have following object :
in filters:
fiscal period object, with an user entry variable on it (UE_MONTH)
in rows/ratios:
Current month column, with your KF and a restriction on 0calmonth2 with an customer exit variable on it (ie: CE_VAR1)
same for April column. (CE_VAR2)
in your customer exit, CMOD, step 2, add these two cases :
WHEN 'CE_VAR1'.
READ TABLE i_t_var_range WITH KEY vnam = 'UE_MONTH' INTO
intern_range.
CONCATENATE intern_range-low(6) sy-datum+4(2) INTO l_s_range-low.
l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
APPEND l_s_range TO e_t_range.
Same for April, add a new case and just replace sy-datum+4(2) by '04'.
Hope it helps, -
Current month and Previous Month
Hi, I have the table shown above. I m trying to get output something like I need current month total amount and the total of the previous month. Can someone please help on this? THank you
ID PreviousMonthTotal CurrentMOnthTotal
1 3000 3000Please say your @@version,
on
Microsoft SQL Server 2012 (SP1) - 11.0.3412.0 (X64)
Mar 2 2014 01:25:09
Copyright (c) Microsoft Corporation
Standard Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
query show ZEROS.
DECLARE @TEMP as TABLE
id int,date_t datetime,amount int
INSERT @TEMP (id,date_t,amount)
VALUES (1,'20150112',1000)
,(1,'20150212',1000)
,(1,'20150122',2000)
,(1,'20150202',200)
,(1,'20160112',41000)
,(2,'20150112',1001)
,(2,'20150212',1003)
,(2,'20150122',2004)
,(2,'20150202',205)
,(2,'20160112',41020)
,(2,'20160212',11200)
,(2,'20140122',201)
,(2,'20140202',20)
SELECT ID as [Cust Ref]
, SUM(CASE WHEN Date_t = dateadd(MM,-1,getdate()) THEN Amount ELSE 0 END) as [Total LAST Month]
, SUM(CASE WHEN Date_t = getdate() THEN Amount ELSE 0 END) as [Total This Month]
FROM @temp
GROUP BY ID -
Show current month and previous month measures
Experts,
My period names are stored like this in the Period Dim table 'Jan 2012'.....'Aug 2012', ... 'Dec 2012' etc..
To my request, i will pass only the current period value via. a drop down prompt, say 'Feb 2013' and it has to apply filter like this Period."Period name" in ('Feb 2013', 'Jan 2013').
I cannot use TIMESTAMPADD(SQL_TSI_MONTH, -1, Period."period name") as my period name is a char. Can someone suggest any idea?
Version : 10.1.3.4
Regards,
SarvanHi,
This can be achived,but little bit tedious process...
Create an intermediate report with three columns.
first column : Monthcolumn,which you are using in prompt.
Second column :This column is for selected month
Try to convert Jan 2012 to 201201,Feb 2012 to 201202...This can be achieved by writing a case statement like below
cast((Case when substring(column from 1 for 3)='Jan' then 01...........)||substring(column from 5 for 4) as int)
Third column:Prior month
cast((Case when substring(column from 1 for 3)='Jan' then 01...........)||substring(column from 5 for 4) as int)-1
Now add the same column formula to the main report and hide it(let's say column name will be "HIDED")
cast((Case when substring(column from 1 for 3)='Jan' then 01...........)||substring(column from 5 for 4) as int)
Now you can apply filter based on another request on the hided column.
HIDED<=Second column in intermediate report.
HIDED>=Third column in intermediate report.
Now you will get the desired reults in your report.
Hope this helps.
Thanks,
Pramod. -
How to compare a Date data with Current Year and Period Member on FIX
Hi experts,
I have a Project dim that each member is a Project (P01, P02...)
and Account dim that stores information of the each Project (Name, Start date, Finished Date...)
Finished Date member is in Date data type
So how can write a IF condition below in order to compare Project Finished Date with Current Year and Period members on FIX
FIX (@Descendants(Projects), Descendants(All Year), Descendants("Year Total")...)
IF (@CURRMBR(Period)->@CURRMBR(Year) < Project->FinishedDate)
Do something...
Else
Do something
Please help me on this. Sorry for my bad grammar. Please ask if there is anything unclear
Many thanks,
Huy Van.
Edited by: Huy Van on Jan 29, 2013 1:14 AM
Edited by: Huy Van on Jan 29, 2013 2:24 AM
Edited by: Huy Van on Jan 29, 2013 2:25 AM
Edited by: Huy Van on Jan 29, 2013 6:04 PMHere is what I have done. Post for whom may concern later
VAR FM; /* Finished Month of Project*/
VAR FY; /* Finished Year of Project */
VAR CM; /* Capture Current Month on FIX statments */
VAR CY; /* Capture Current Year on FIX statments*/
FIX ( @RELATIVE( "Year", 0), @RELATIVE( "Period", 0), @IDescendants( "Base Projects")....)
FY = @ROUND( "TGHT"->"NA Contract"->"FY06"->"NA Period" / 10000, 0);
FM = @MOD( @ROUND( "TGHT"->"NA Contract"->"FY06"->"NA Period" / 100, 0), 100);
/* For FY13 return 13... */
CY = @JgetDoubleFromString( @CONCATENATE( "20", @SUBSTRING( @NAME( @CURRMBRRANGE( Year, Lev, 0, 0, 0)), 2)));
/* Set CM value based on currrent Period On FIX statement */
IF ( @ISMBR( "Jan"))
CM = 1;
ELSEIF ( @ISMBR( "Feb"))
CM = 2;
ELSEIF ( @ISMBR( "Dec"))
CM = 12;
ENDIF
IF ( CY < FY OR ( CY == FY AND CM < FM))
Do something...
ELSE
Do something...
ENDIF
ENDFIX
Edited by: Huy Van on Feb 19, 2013 11:10 PM
Edited by: Huy Van on Feb 20, 2013 7:46 PM -
How to get data for current week and previous week using customer exit in Bex.
Hi everyone,
I have a scenario in which I need to display data for current week and previous week (based on "sy_datum" the program has to calculate current week and previous week) in Bex using Customer exit. I have created one variable in Bex Query Designer and I have written code for the variable in CMOD. But it is not working fine, (I know that we can do the same by using offset value in Bex). Can some one guide me how to achieve my requirement using customer exit.
Thanks in Advance,
G S Ramanjaneyulu.Hi krishna,
Thanks for your quick reply, can you have a look at my code,
case i_vnam.
WHEN 'ZPWK_CWK'.
ranges : pre_week for sy-datum.
data : start_date type DATS,
end_date TYPE dats .
************FM TO GET FIRST DATE OF CURRENT WEEK ************************
CALL FUNCTION 'BWSO_DATE_GET_FIRST_WEEKDAY'
EXPORTING
DATE_IN = sy-datum
IMPORTING
DATE_OUT = start_date. " WEEK FIRST DATE
end_date = START_DATE + 6. " WEEK LAST DATE
END_DATE = START_DATE - 1. " PREVIOUS WEEK END DATE
START_DATE = START_DATE - 7. " PREVIOUS WEEK START DATE
**********PREVIOUS WEEK DATES IN PRE_WEEK******************
pre_week-SIGN = 'I'.
pre_week-option = 'BT'.
pre_week-LOW = START_DATE.
pre_week-HIGH = END_DATE.
APPEND pre_week.
CLEAR : START_DATE,END_DATE.
endcase.
Regards,
G S Ramanjaneyulu. -
When I got my new iPhone and was trying to switch everything over I accidentally set up a new icloud account with one email and had one on my old iphone with another account. Does anyone know how I can merge the two accounts?
You cannot merge Apple IDs but you can go to Settings > iCloud and 'Delete Account'. When prompted to turn off documents and data, choose the only option which is Delete from my iPhone, but on the other prompt for Contacts, Calendars, etc you can choose 'Keep on my iPhone' Then once the Account is Deleted form the iPhone, log back in with the correct Apple ID and choose Merge when prompted. This will merge your data from this iPhone with that iCloud account effectively putting your devices on the same account.
-
How to fetch year till date value for earning for current ,last and year
hi,
how to fetch year till date value for earning for current ,last and year before that from payroll result
plz reply soon,
pratyushDear Pratyush,
Pick this from CRT.
Use LDB PNPCE & Fire event GET PAYROLL &
then you can pick from CRT.
Hope this helps.
Kindly reward in case useful.
Regards & Thanks,
Darshan Mulmule -
Displaying current year and previous year's data.
hi all,
we have fields like doc.no, company code, costcenter, posting date, year etc... in a query.
we are using this query to display data in VC,
how can i display the current year and previous year's data in two different tables using the available fields.
any help will be highly appreciated.
thanks,
RkHi Rk,
You can achieve your requirement using 'Filter' operator. Drag one 'Filter' operator into visual composer story board and drag the output into filter and add condition(Check year=2008) and drag one table from filter. For another table use another filter and change the condition.
Hope it helps...
Regards
Basheer -
How to display records based on current month and last month???
i have a query that want to display the data for current month and last month. when i try to view the reports, all the data/key figures is return all in 0.00.
i modify the variables for this current month and last month but still the results is the same. i could not see the data. any advise on how to modify the variables for this current month and last month? i am thinking my variables is wrong.
for the current month variable:
the type of variable is characteristic value, processing by customer exit, reference characteristic is calendar year/month.
thanks for all who are kind to help me here....Hi,
If you install the variables from BC correctly and they are in active state, you can use them directly use them. check for this month the total values at info cube is ZERO or some value. as you told you are getting ZEROS for your input.and check the data at cube level based on your query design, apply all restrictions, fileters and see do you get any data at cube level and compare with report. -
BEx - Display current year and previous year by day on the same row
Hello experts, need some help/suggestions on how I can accomplish the following please.
We have a requirement to show MTD revenue by day for the current year and previous year. The desired result will have the following columns
Calendar Day | Current MTD Revenue | Prev MTD Revenue
11/01/2009 | 15,131,005 | 15,138,668
11/02/2009 | 15,055,345 | 15,523,762
However, the result is showing up as follows:
Calendar Day | Current MTD Revenue | Prev MTD Revenue
11/01/2008 | | 15,138,668
11/02/2008 | | 15,523,762
11/01/2009 | 15,131,005 |
11/02/2009 | 15,055,345 |
The number of rows for Calendar Day varies depending on the date the user selects. We only want to display the days for the current year with the Previous Year Column on the same row.
Can someone please let me know how I can get the results to display on one line for each day?
Thanks,
DavidI have the same issue on my end, and am interested in responses. I searched the forum and found this suggestion in another post; not sure if this solution will help, but it looks like it might. This was a response from poster RadhaN:
RadhaN
Posts: 390
Registered: 8/27/09
Forum Points: 876
Re: a simple query to show sales versus last year on daily basis/
Posted: Sep 21, 2009 9:53 AM in response to: Shlomi Weiss Reply
HI Shlomi
Create a virtual characteristic in your infoprovider that can calculate the day from calendar Day. In ZXRSRZZZ while adding code for this virtual characteristic use the function module DATE_COMPUTE_DAY to compute the day for every calendar day.
For calculating Sales Current year, create a restricted ky figure with Sales as the key figure. Add 0CalDay to this RKF and create a variable for this infoobject(Eg: ZCURYEAR) that will receive input from the user for the range of dates eg: 08/16/2009 - 08/22/2009.
For Sales Prior year, create another restricted key figure with Sales. Add 0CalDay to this RKF and add a customer exit variable. In the Customer exit code use the ZCURYEAR variable and offset it to prior year in both the upper and lower limits. This should work.
I hope this helps.
Thanks. -
Difference between current row and previous row in a table
Hi All,
I am having a problem with the query. Can some of please help me?
I need to get difference between current row and previous row in a table. I have a table, which have data like bellow.
TABLEX
================
Name Date Items
AAA 01-SEP-09 100
BBB 02-SEP-09 101
CCC 03-SEP-09 200
DDD 04-SEP-09 200
EEE 05-SEP-09 400
Now I need to get output like bellow...
Name Date Items Diff-Items
AAA 01-SEP-09 100 0
BBB 02-SEP-09 101 1
CCC 03-SEP-09 200 99
DDD 04-SEP-09 200 0
EEE 05-SEP-09 400 200
Can some one help me to write a query to get above results?
Please let me know if you need more information.
Thanks a lot in advance.
We are using Oracle10G(10.2.0.1.0).
Thanks
Asif, nvl (items - lag (items) over (order by dt), 0)like in
SQL> with test as
2 (
3 select 'AAA' name, to_date('01-SEP-09', 'dd-MON-rr') dt, 100 items from dual union all
4 select 'BBB' name, to_date('02-SEP-09', 'dd-MON-rr') dt, 101 items from dual union all
5 select 'CCC' name, to_date('03-SEP-09', 'dd-MON-rr') dt, 200 items from dual union all
6 select 'DDD' name, to_date('04-SEP-09', 'dd-MON-rr') dt, 200 items from dual union all
7 select 'EEE' name, to_date('05-SEP-09', 'dd-MON-rr') dt, 400 items from dual
8 )
9 select name
10 , dt
11 , items
12 , nvl (items - lag (items) over (order by dt), 0)
13 from test
14 ;
NAM DT ITEMS NVL(ITEMS-LAG(ITEMS)OVER(ORDERBYDT),0)
AAA 01-SEP-09 100 0
BBB 02-SEP-09 101 1
CCC 03-SEP-09 200 99
DDD 04-SEP-09 200 0
EEE 05-SEP-09 400 200
SQL> -
Key figure comparision between current year and previous year
Hello collegues,
I have created a WEB Intelligence report with key figure ROI (return on investment which is calculated out of three other key figures (capital, revenue and costs). I would now like to calculate the percentage period (year) differences between key figure ROI - between current year (month) and previous year (month).
Do I have to add coding within a key figure formula within WEBI Rich Tech client or within universe builder.
The key figures were extracted from SAP BW and added to a universe which is basis for WEBI rich tech client report.
thanks and regards,
ChristianHi Stratos,
so I see - i have to use the variable Editor and then define a measure and add coding in the formula field. Do you have an e-mail address ín order to send you the report and explain in more detail what I would like to see - here it is not possible to upload a report...
thanks and regards,
Christian -
Current year and previous year
Hi All Grus,
i have a one requirement user will give input 30.04.2009 . the output should show last ten days including user entered date like 21.04.2009 to 30.04.2009 for current year and previous year
this current year and previous should show column wise in row wise i need year like given below
user input: 30.04.2009
row column
21.04.09 22..04.09. 23..04.09 .............................................................. 30.04.2009
2009 100 200 300 ............................................................... 500
2008 200 300 600 ................................................................. 1000
Edited by: kek.uthayakumar on Aug 4, 2009 7:57 AM
Edited by: kek.uthayakumar on Aug 4, 2009 7:58 AMHi
You need to have customer exit variable on this calday and write code to obtain your logic. Search in SDN for sample codes:
enter information required in search forum SAP Business Explorer (SAP BEx)
Regards
Ravi
Maybe you are looking for
-
Problem with Windows 7 on Mac Pro 3,1
I am trying to install Windows 7 to a seperate HDD an on Mac Pro 3,1 and have run into a problem getting it to work. To start with I had a 500GB HDD which was partitioned using Bootcamp assistant and had OSX 10.6,8 and Windows 7 installed on it and w
-
Erasing Time Machine hard drive after formatting for both PPC and Intel
Ok, I made a mistake. First I formatted a Western Digital 500 gig hard drive for both my wife's PPC G4 laptop and my own Intel MBP laptop, so we could both use Leopard's Time Machine for backing up to the same drive. That wasn't my mistake though, it
-
My 80 gig iPod was full, so I bought a 160gig. I just kept the 80 gig one with the songs on it and just recharged it. When I tried to re-sync it I was told 1 iPod per iTunes library. I tried anyway by just checking songs to be synced. Now my 80 gig i
-
Command Line Support Not Working in OSD
I am trying to deploy an image to a dell optiplex 760. I have added all of the storage and nic drivers from Dell's WINPE package, and then all of the drivers from the Intel site for the nic to my boot image. I then enabled command line support on the
-
Finding Field Name for Data in Transaction Title
Hi everyone. I am a BW developer and I need to extract information which is available in SAP R/3's transaction title. Here's some information: Transaction code: <b>ME23N</b> Transaction Title: Stock transport ord. 1100000000 Created by <b>John Doe</b