Calculate no of saturdays in a year
Hi,
I'm using oracle 10.2.0.1.0
Is it possible to get the number of saturdays in a year , with a single sql?
Say, i want to find the no of saturdays in 2012, with single sql i have to get as 52.
Thanks
Hi,
Another way:
SELECT CASE
WHEN TO_CHAR ( TRUNC (DATE '2012-01-01', 'YEAR')
, 'DY'
, 'NLS_DATE_LANGUAGE=ENGLISH' -- If needed
) = 'SAT'
OR TO_CHAR ( 59 + TRUNC (DATE '2012-01-01', 'YYYY')
, 'DY MON DD'
, 'NLS_DATE_LANGUAGE=ENGLISH' -- If needed
) = 'MON FEB 29'
THEN 53
ELSE 52
END AS num_saturdays
FROM dual
;Instead of the date literal (DATE '2012-01-01') you can use any date(s) in the year you want to test.
Similar Messages
-
How to calculate no of days in an year
Hi,
can some one provide a simple way to calculate no of days in a year if we know processing date.
thanks
CDPrasadselect
trunc(input_date, 'YYYY') as the_year,
add_months(trunc(input_date, 'YYYY'), 12)
trunc(input_date, 'YYYY') as days_in_year
from
select
add_months(sysdate, -12 * level) as input_date
from dual
connect by level <= 20
12 );
THE_YEAR DAYS_IN_YEAR
01-JAN-2009 12 00:00 365
01-JAN-2008 12 00:00 366
01-JAN-2007 12 00:00 365
01-JAN-2006 12 00:00 365
01-JAN-2005 12 00:00 365
01-JAN-2004 12 00:00 366
01-JAN-2003 12 00:00 365
01-JAN-2002 12 00:00 365
01-JAN-2001 12 00:00 365
01-JAN-2000 12 00:00 366
01-JAN-1999 12 00:00 365
01-JAN-1998 12 00:00 365
01-JAN-1997 12 00:00 365
01-JAN-1996 12 00:00 366
01-JAN-1995 12 00:00 365
01-JAN-1994 12 00:00 365
01-JAN-1993 12 00:00 365
01-JAN-1992 12 00:00 366
01-JAN-1991 12 00:00 365
01-JAN-1990 12 00:00 365
20 rows selected.
TUBBY_TUBBZ?The above shows the number of days in a year for the past 20 years.
So assuming you had a variable .. called "input_date"
trunc(input_date, 'YYYY') as the_year,
add_months(trunc(input_date, 'YYYY'), 12)
trunc(input_date, 'YYYY') as days_in_year Would do it. -
Query to print all second saturdays of current year
Hi
I need help to write a query that prints all the second saturdays of current year.
Please help me.
Thanks in advance,Quote:
DATE1
14-JAN-06
11-FEB-06
11-MAR-06
08-APR-06
15-APR-06
13-MAY-06
10-JUN-06
08-JUL-06
15-JUL-06
12-AUG-06
10 rows selected.This selects 2 rows fewer than there are months in the year. You've got 2 second saturdays in both April and July.
Quote:
MS
14-JAN-06
11-FEB-06
11-MAR-06
15-APR-06
13-MAY-06
10-JUN-06
15-JUL-06
12-AUG-06
09-SEP-06
14-OCT-06
11-NOV-06
09-DEC-06
12 rows selected.The 15th of a month cannot possibly be the second Saturday!
Try
SQL> select date1 from (select to_date('01/01/2006', 'DD/MM/YYYY') + rownum -1 date1
2 from all_objects
3 where rownum <= 365)
4 where to_number(to_char(date1, 'DD')) between 8 and 14
5 and to_char(date1, 'DY') = 'SAT'
6 ;
DATE1
14-JAN-06
11-FEB-06
11-MAR-06
08-APR-06
13-MAY-06
10-JUN-06
08-JUL-06
12-AUG-06
09-SEP-06
14-OCT-06
11-NOV-06
09-DEC-06
12 rows selected. -
How to calculate the data as per accounting year
I want to dispaly the result for the accounting year from April to March for any accounting year (Accounting year is from April to March).
I have a table INVOICE.
CREATE TABLE INVOICE
IN_NO NUMBER,
IN_DT DATE,
IN_DETAILS VARCHAR2(20 BYTE)
I want to calculate display the result for accounting year from April 2010 to March 2011, and from April 2011 to MArch 2012.
What statement should i use to filter the data as above ?
Sanjayuser12957777 wrote:
I want to dispaly the result for the accounting year from April to March for any accounting year (Accounting year is from April to March).
I have a table INVOICE.
CREATE TABLE INVOICE
IN_NO NUMBER,
IN_DT DATE,
IN_DETAILS VARCHAR2(20 BYTE)
I want to calculate display the result for accounting year from April 2010 to March 2011, and from April 2011 to MArch 2012.
What statement should i use to filter the data as above ?
Sanjay
You should learn now to use correct tags
select to_char(add_months(in_dt,-3),'YYYY') FISCAL_YEAR FROM INVOICE; -
Find HOW MANY Saturdays IN A YEAR
Dear Experts,
I have to display the number of SATURSDAYS in a YEAR .
How I can do it ?
Thanks in advance.
Moderator message: date calculation questions = FAQ, please search before posting.
locked by: Thomas Zloch on Sep 8, 2010 12:00 PMHi,
Just try the below given code by giving year as input.
PARAMETERS:p_year(4) type n.
data: date type d,
ndate type d,
rem type i,
count type i.
date+0(4) = p_year.
date+4(2) = 01.
date+6(2) = 01.
rem = p_year mod 4.
if rem eq 0.
ndate = date + 366.
else.
ndate = date + 365.
endif.
clear rem.
while date+0(4) eq p_year.
move date to rem.
rem = rem - 1.
rem = rem mod 7.
if rem eq 6.
count = count + 1.
ENDIF.
date = date + 1.
ENDWHILE.
write:/ 'N.o of saturdays are ',count.
It is helpful. -
Calculate week no based on financial year
Hi
Financial year starts with 01-Apr . I need to calculate week no based on 01-APR(financial year) not 01-Jan
for each date. Is there a way to calculate based on thisIt works for all year long :-)
SQL> ed
Wrote file afiedt.buf
1 with testdata as (
2 select date '2011-04-01' + 7 * (level-1) dt from dual
3 connect by level <= 60
4 )
5 --
6 -- End of test data
7 --
8 select
9 to_char(dt,'YYYY-MM-DD') the_date,
10 to_char(add_months(dt,-3),'WW') fiscal_week,
11 to_char(add_months(dt,-3),'IW') iso_fiscal_week
12 from testdata
13* order by dt
SQL> /
THE_DATE FI IS
2011-04-01 01 52
2011-04-08 02 01
2011-04-15 03 02
2011-04-22 04 03
2011-04-29 05 04
2011-05-06 06 05
2011-05-13 07 06
2011-05-20 08 07
2011-05-27 09 08
2011-06-03 09 09
2011-06-10 10 10
2011-06-17 11 11
2011-06-24 12 12
2011-07-01 13 13
2011-07-08 14 14
2011-07-15 15 15
2011-07-22 16 16
2011-07-29 17 17
2011-08-05 18 18
2011-08-12 19 19
2011-08-19 20 20
2011-08-26 21 21
2011-09-02 22 22
2011-09-09 23 23
2011-09-16 24 24
2011-09-23 25 25
2011-09-30 26 26
2011-10-07 27 27
2011-10-14 28 28
2011-10-21 29 29
2011-10-28 30 30
2011-11-04 31 31
2011-11-11 32 32
2011-11-18 33 33
2011-11-25 34 34
2011-12-02 35 35
2011-12-09 36 36
2011-12-16 37 37
2011-12-23 38 38
2011-12-30 39 39
2012-01-06 40 40
2012-01-13 41 41
2012-01-20 42 42
2012-01-27 43 43
2012-02-03 44 44
2012-02-10 45 45
2012-02-17 46 46
2012-02-24 47 47
2012-03-02 48 48
2012-03-09 49 49
2012-03-16 50 50
2012-03-23 51 51
2012-03-30 52 52
2012-04-06 01 01
2012-04-13 02 02
2012-04-20 03 03
2012-04-27 04 04
2012-05-04 05 05
2012-05-11 06 06
2012-05-18 07 07
60 rows selected.ISO Week (IW) works with a different way of defining week 01. Using IW April 1st will become week 52. You will have to decide if that is correct according to your finance department :-) -
How to calculate Sales percentage difference between selected year and its previous year in a Matrix
Hi,
I'm trying to generate a report using matrix like this
Month
Product PreviousYearSalesAmount SelectedYearSalesAmount %SalesDifference
I can populate year sales amount, but i cant calculate the percentage.
Can Anyone help me please.
Note: Month and Year are passed as parameters.
Thank you.Hi Abhiram,
As per my understanding you can show your fields in matrix.
Only problem is to create the additional column which will have the %SalesDifference value right?
If yes,
Just create one column as shown in below screen,
It will create one column, Name the header of this newly created column as %SalesDifference
In below this header , where you want to show the value for %SalesDifference as
=sum(iif(Fields!year.Value=Parameters!year.Value,(Fields!SalesAmount.Value),-Fields!SalesAmount.Value))/Fields!SalesAmount.Value
Set the property of the column in number as Percentage.
run the report, you will see as below screen.
For your reference I am attaching my RDL code, you can save as .rdl file and run the report (sample Data inside the report only)
<?xml version="1.0" encoding="utf-8"?>
<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
<Body>
<ReportItems>
<Textbox Name="textbox1">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>Matrix</Value>
<Style>
<FontFamily>Tahoma</FontFamily>
<FontSize>14pt</FontSize>
<FontWeight>Bold</FontWeight>
<Color>SteelBlue</Color>
</Style>
</TextRun>
</TextRuns>
<Style>
<TextAlign>Center</TextAlign>
</Style>
</Paragraph>
</Paragraphs>
<rd:DefaultName>textbox1</rd:DefaultName>
<Height>0.37in</Height>
<Width>5in</Width>
<Style>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
<Tablix Name="Tablix1">
<TablixCorner>
<TablixCornerRows>
<TablixCornerRow>
<TablixCornerCell>
<CellContents>
<Textbox Name="Textbox16">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>Product</Value>
<Style>
<FontWeight>Bold</FontWeight>
</Style>
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Textbox16</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<BackgroundColor>LightBlue</BackgroundColor>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</CellContents>
</TablixCornerCell>
</TablixCornerRow>
<TablixCornerRow>
<TablixCornerCell>
<CellContents>
<Textbox Name="Textbox17">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value />
<Style>
<FontWeight>Bold</FontWeight>
</Style>
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Textbox17</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</CellContents>
</TablixCornerCell>
</TablixCornerRow>
</TablixCornerRows>
</TablixCorner>
<TablixBody>
<TablixColumns>
<TablixColumn>
<Width>1.79722in</Width>
</TablixColumn>
<TablixColumn>
<Width>1.76722in</Width>
</TablixColumn>
</TablixColumns>
<TablixRows>
<TablixRow>
<Height>0.25in</Height>
<TablixCells>
<TablixCell>
<CellContents>
<Textbox Name="SalesAmount">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=Sum(Fields!SalesAmount.Value)</Value>
<Style />
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>SalesAmount</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</CellContents>
</TablixCell>
<TablixCell>
<CellContents>
<Textbox Name="Textbox76">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=sum(iif(Fields!year.Value=Parameters!year.Value,(Fields!SalesAmount.Value),-Fields!SalesAmount.Value))/Fields!SalesAmount.Value</Value>
<Style>
<Format>0.00%</Format>
</Style>
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Textbox76</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</CellContents>
</TablixCell>
</TablixCells>
</TablixRow>
</TablixRows>
</TablixBody>
<TablixColumnHierarchy>
<TablixMembers>
<TablixMember>
<Group Name="month">
<GroupExpressions>
<GroupExpression>=Fields!month.Value</GroupExpression>
</GroupExpressions>
</Group>
<SortExpressions>
<SortExpression>
<Value>=Fields!month.Value</Value>
</SortExpression>
</SortExpressions>
<TablixHeader>
<Size>0.25in</Size>
<CellContents>
<Textbox Name="month1">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=MonthName(Fields!month.Value)</Value>
<Style>
<FontWeight>Bold</FontWeight>
</Style>
</TextRun>
</TextRuns>
<Style>
<TextAlign>Center</TextAlign>
</Style>
</Paragraph>
</Paragraphs>
<rd:DefaultName>month1</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<BackgroundColor>LightBlue</BackgroundColor>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</CellContents>
</TablixHeader>
<TablixMembers>
<TablixMember>
<Group Name="year">
<GroupExpressions>
<GroupExpression>=Fields!year.Value</GroupExpression>
</GroupExpressions>
</Group>
<SortExpressions>
<SortExpression>
<Value>=Fields!year.Value</Value>
</SortExpression>
</SortExpressions>
<TablixHeader>
<Size>0.25in</Size>
<CellContents>
<Textbox Name="year">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=Fields!year.Value</Value>
<Style>
<FontWeight>Bold</FontWeight>
</Style>
</TextRun>
</TextRuns>
<Style>
<TextAlign>Center</TextAlign>
</Style>
</Paragraph>
</Paragraphs>
<rd:DefaultName>year</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</CellContents>
</TablixHeader>
<TablixMembers>
<TablixMember />
</TablixMembers>
</TablixMember>
</TablixMembers>
</TablixMember>
<TablixMember>
<TablixHeader>
<Size>0.25in</Size>
<CellContents>
<Textbox Name="Textbox61">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>%SalesDifference</Value>
<Style>
<FontStyle>Normal</FontStyle>
<FontWeight>Bold</FontWeight>
<TextDecoration>None</TextDecoration>
<Color>#000000</Color>
</Style>
</TextRun>
</TextRuns>
<Style>
<TextAlign>Center</TextAlign>
</Style>
</Paragraph>
</Paragraphs>
<rd:DefaultName>Textbox61</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<BackgroundColor>LightBlue</BackgroundColor>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</CellContents>
</TablixHeader>
<TablixMembers>
<TablixMember>
<TablixHeader>
<Size>0.25in</Size>
<CellContents>
<Textbox Name="Textbox62">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value />
<Style>
<FontWeight>Bold</FontWeight>
</Style>
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Textbox62</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</CellContents>
</TablixHeader>
</TablixMember>
</TablixMembers>
</TablixMember>
</TablixMembers>
</TablixColumnHierarchy>
<TablixRowHierarchy>
<TablixMembers>
<TablixMember>
<Group Name="Product">
<GroupExpressions>
<GroupExpression>=Fields!Product.Value</GroupExpression>
</GroupExpressions>
</Group>
<SortExpressions>
<SortExpression>
<Value>=Fields!Product.Value</Value>
</SortExpression>
</SortExpressions>
<TablixHeader>
<Size>1.38889in</Size>
<CellContents>
<Textbox Name="Product1">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=Fields!Product.Value</Value>
<Style />
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Product1</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</CellContents>
</TablixHeader>
</TablixMember>
</TablixMembers>
</TablixRowHierarchy>
<DataSetName>DataSet1</DataSetName>
<Top>0.38in</Top>
<Left>0.04667in</Left>
<Height>0.75in</Height>
<Width>4.95333in</Width>
<ZIndex>1</ZIndex>
<Style>
<Border>
<Style>None</Style>
</Border>
</Style>
</Tablix>
</ReportItems>
<Height>1.20167in</Height>
<Style />
</Body>
<Width>5.1in</Width>
<Page>
<LeftMargin>1in</LeftMargin>
<RightMargin>1in</RightMargin>
<TopMargin>1in</TopMargin>
<BottomMargin>1in</BottomMargin>
<Style />
</Page>
<AutoRefresh>0</AutoRefresh>
<DataSources>
<DataSource Name="DataSource1">
<DataSourceReference>DataSource1</DataSourceReference>
<rd:SecurityType>None</rd:SecurityType>
<rd:DataSourceID>501ee6de-61fb-416f-9a92-011661d01cba</rd:DataSourceID>
</DataSource>
</DataSources>
<DataSets>
<DataSet Name="DataSet1">
<Query>
<DataSourceName>DataSource1</DataSourceName>
<QueryParameters>
<QueryParameter Name="@year">
<Value>=Parameters!year.Value</Value>
</QueryParameter>
<QueryParameter Name="@Month">
<Value>=Parameters!Month.Value</Value>
</QueryParameter>
</QueryParameters>
<CommandText>select * from
select 'apple' Product ,1 month ,2014 year,2000 SalesAmount
union
select 'apple' Product ,1 month,2015 year,3000 SalesAmount
union
select 'dell' Product ,1 month,2014 year,3000 SalesAmount
union
select 'dell' Product ,1 month,2015 year,2500 SalesAmount
union
select 'apple' Product ,2 month,2014 year,1500 SalesAmount
union
select 'apple' Product ,2 month,2015 year,3000 SalesAmount
union
select 'dell' Product ,2 month,2014 year,3000 SalesAmount
union
select 'dell' Product ,2 month,2015 year,5500 SalesAmount
)t
where year between @year-1 and @year
and Month=@Month</CommandText>
<rd:UseGenericDesigner>true</rd:UseGenericDesigner>
</Query>
<Fields>
<Field Name="Product">
<DataField>Product</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name="month">
<DataField>month</DataField>
<rd:TypeName>System.Int32</rd:TypeName>
</Field>
<Field Name="year">
<DataField>year</DataField>
<rd:TypeName>System.Int32</rd:TypeName>
</Field>
<Field Name="SalesAmount">
<DataField>SalesAmount</DataField>
<rd:TypeName>System.Int32</rd:TypeName>
</Field>
</Fields>
</DataSet>
</DataSets>
<ReportParameters>
<ReportParameter Name="year">
<DataType>String</DataType>
<DefaultValue>
<Values>
<Value>2015</Value>
</Values>
</DefaultValue>
<Prompt>year</Prompt>
</ReportParameter>
<ReportParameter Name="Month">
<DataType>String</DataType>
<DefaultValue>
<Values>
<Value>1</Value>
</Values>
</DefaultValue>
<Prompt>Month</Prompt>
</ReportParameter>
</ReportParameters>
<Language>en-US</Language>
<ConsumeContainerWhitespace>true</ConsumeContainerWhitespace>
<rd:ReportUnitType>Inch</rd:ReportUnitType>
<rd:ReportID>ee1a8383-6595-42b1-94f2-c68d681c85d3</rd:ReportID>
</Report>
Thanks
Prasad
Mark this as Answer if it helps you to proceed on further. -
How to calculate 10% of depreciation for first year and 20% going forward
Certain categories are using flat rate depreciation. One category requires 10% of depreciation to be calculated in the first year of addition and 20% going forward. How to define this in Oracle?
ThanksHello.
Create a depreciation method with Method Type = Table.
Octavio -
How to calculate Number of weeks in Year ?? urgent
hi gurus,
i have to calculate the number of weeks in year. could you please suggest me is there any function module for that or do we need to create variable to get the number of weeks?
regardsGet some pointers frm
http://sap.ittoolbox.com/groups/technical-functional/sap-dev/help-on-function-day_get_week-1067350
Re: printing calender
Calculating the number of days of a year including leap year
Re: How to calculate No.of Weeks? -
Month vs PY year measure in custom calendar
Dear All
I have go two RELATED tables in my Powerpivot data model:
Table: PTV FLAT HITLIST
COUNTRY
BRAND
TV MODEL
INCH SIZE
SALES THS#EUR
PERIOD
HUNGARY
PANASONIC
TX-L32C20
32
100
2012 JUN
HUNGARY
SHARP
LC-32SH7EBK
32
101
2012 JUN
HUNGARY
TRADEBRAND
TRADE MODEL
32
102
2012 JUN
POLAND
FUNAI
LH840-M32
32
103
2012 JUN
POLAND
FUNAI
LT6-M32
32
104
2012 JUN
Table: PERIOD
PERIOD
PERIOD NUMBER
MONTH NUMBER
DATE
FISCAL QUATER
FIRST PERIOD IN YEAR
FISCAL YEAR
2012 JAN
01
1
2012-01
Q4
1
2011
2012 FEB
02
2
2012-02
Q4
1
2011
2012 MAR
03
3
2012-03
Q4
1
2011
2012 APR
04
4
2012-04
Q1
4
2012
2012 MAY
05
5
2012-05
Q1
4
2012
2012 JUN
06
6
2012-06
Q1
4
2012
2012 JUL
07
7
2012-07
Q2
4
2012
2012 AUG
08
8
2012-08
Q2
4
2012
2012 SEP
09
9
2012-09
Q2
4
2012
2012 OCT
10
10
2012-10
Q3
4
2012
2012 NOV
11
11
2012-11
Q3
4
2012
2012 DEC
12
12
2012-12
Q3
4
2012
2013 JAN
13
1
2013-01
Q4
4
2012
2013 FEB
14
2
2013-02
Q4
4
2012
2013 MAR
15
3
2013-03
Q4
4
2012
2013 APR
16
4
2013-04
Q1
16
2013
2013 MAY
17
5
2013-05
Q1
16
2013
2013 JUN
18
6
2013-06
Q1
16
2013
First one is quite big so I present only part. There are more columns with sales facts and product's features which was hidden to keep it more clear.
What I need is to have a measure which describes a month other month sales. So for example:
JAN 2014 JAN 2013 DIFF VS PY
200 eur 150 EUR 1,333
So the expected result is 1,33
I wrote a measure:
DIFF VS PY:=CALCULATE(SUM([SALES THS#EUR]),FILTER(PERIOD,MAX(PERIOD[FISCAL YEAR])))/CALCULATE(SUM([SALES THS#EUR]),ALL(PERIOD[FISCAL YEAR]),FILTER(ALL(PERIOD[FISCAL YEAR]),PERIOD[FISCAL YEAR]=MAX(PERIOD[FISCAL YEAR])-1))-1
which works on Total, but not months. On a pivot table it looks like this:
Row Labels
SALES THS EUR
DIFF VS PY
2011
454,777
2012-01
190,961
2012-02
136,252
2012-03
127,564
2012
2,071,222
355%
2012-04
121,442
2012-05
148,521
2012-06
139,187
2012-07
144,297
2012-08
132,714
2012-09
142,333
2012-10
194,294
2012-11
232,935
2012-12
339,444
2013-01
184,280
2013-02
138,139
2013-03
153,636
2013
2,002,603
-3%
2013-04
131,322
2013-05
157,068
2013-06
124,342
2013-07
132,663
2013-08
124,874
2013-09
142,968
2013-10
178,709
2013-11
227,422
2013-12
324,105
2014-01
195,916
2014-02
139,371
2014-03
123,843
2014
765,310
-62%
How to correct the measure to work on months too?
I have tried this but not working (returns blanks):
Copy of DIFF VS PY:=CALCULATE(SUM([SALES THS#EUR]),FILTER(PERIOD,MAX(PERIOD[PERIOD NUMBER])))/CALCULATE(SUM([SALES THS#EUR]),ALL(PERIOD[PERIOD NUMBER]),FILTER(ALL(PERIOD[PERIOD NUMBER]),PERIOD[PERIOD NUMBER]=MAX(PERIOD[PERIOD NUMBER])-12))-12
G.Try this:
Sales:=
SUM( 'PTV FLAT HITLIST'[SALES THS#EUR] )
PY Sales:=
CALCULATE(
[Sales]
, FILTER( ALL( PERIOD[FISCAL YEAR] )
, PERIOD[FISCAL YEAR] = MAX( PERIOD[FISCAL YEAR] ) - 1
Sales vs PY Sales:=
[Sales] / [PY Sales]
This will work if you put PERIOD[MONTH NUMBER] on the rows under PERIOD[FISCAL YEAR].
If you must keep PERIOD[DATE] on the rows, then you'll need to handle this a little differently. PERIOD[DATE] uniquely identifies a month. This means that with the measures I have suggested above, the filter context will not be cleared from PERIOD[DATE]
and so the filter context of CALCULATE() will be an impossible condition:
On Row Label 2014-03, the filter context will be PERIOD[DATE] = 2014-03 && PERIOD[FISCAL YEAR] = 2013.
If you must keep PERIOD[DATE] as your rowfilter, try this:
Sales:=
SUM( 'PTV FLAT HITLIST'[SALES THS#EUR] )
PY Yr Sales:=
CALCULATE( [Sales]
, FILTER( ALL( PERIOD[FISCAL YEAR] )
, PERIOD[FISCAL YEAR] = MAX( PERIOD[FISCAL YEAR] ) - 1
PY Mo Sales:=
CALCULATE( [Sales]
, FILTER( ALL( PERIOD )
, PERIOD[FISCAL YEAR] = MAX( PERIOD[FISCAL YEAR] ) - 1
&& PERIOD[MONTH NUMBER] = MAX( PERIOD[MONTH NUMBER] )
PY Sales:=
IF( ISFILTERED( PERIOD[DATE] )
, [PY Mo Sales]
, [PY Yr Sales]
Sales vs PY Sales:=
[Sales] / [PY Sales] -
SYST Period 012 is not valid in financial year variant R2 Msg no;FGV003
Hi SAP Gurus,
I have encountered with an error as following :
SYST: Period 012 is not valid in financial year variant R2
Message no. FGV003
Our client following calendar year till December 2009. They want to change to April to March , from April 2010 . So we need to define a shortened fiscal year for January to March 2010 for 3 months.
One important thing is Depreciation should be calculated only for 3 months ie., from January 2010 to March 2010 for year 2010. For year 2011 u2013 April 2010 to March 2011 be calculated.
I have done the following settings :
Current fiscal year variant = K4, i.e. the standard variant with 12 periods (calendar year)
-the current fiscal year must be closed on 31.12.2009
-this change have to be done in the next month, i.e. on 01.01.2010
-on 1.1..2010 starts the new fiscal year 2010
-the fiscal year 2010 ends on 31.03.2010 and have 3 posting periods
1) Create a new Fiscal Year Variant for the shortened fiscal year u2013 e.g. "R2" (OB29).
2) R2 to be made Year Dependent. Current Period Configuration
Month Days Period Year Shift
1 31 1 0
2 28 2 0
3 31 3 0
4 30 4 0
5 31 5 0
6 30 6 0
7 31 7 0
8 31 8 0
9 30 9 0
10 31 1 +1
11 30 2 +1
12 31 3 +1
3) Company Code assignment (OB37): K4 to be replaced with R2 .
4) Controlling Area (OKKP): K4 to be replaced with R2.
5) Fiscal Year to be shortened for Depreciation Areas in Asset Accounting customization (OAYP).
6) Table T093C to be viewed to check whether the field XRUMPF (Shortened Fiscal Year) has been activated with u201CXu201D..(SE 11 Check Table) Done manually
Other Problem : 1. The system calculates deprecation for period 3 ( Full year deprecation) as seen from AW01n for one asset.
2. When I run AFAB for 2010 period 1 the error is displayed
SYST: Period 012 is not valid in financial year variant R2
Message no. FGV003
Please anybody help me in this issue .
SubbuHave you maintained the Year Shift Properly in OB29
For e.g if Financial Year is from July to June, year shift will be as follows:
Month Days Period Year Shift
1 31 7 0
2 29 8 0
3 31 9 0
4 30 10 0
5 31 11 0
6 30 12 0
7 31 1 +1
8 31 2 +1
9 30 3 +1
10 31 4 +1
11 30 5 +1
12 31 6 +1
Check also FI period and aseet periods are open through OB52 and AJAB -
Urgent ...! How to get Current Quarter of the Fiscal Year
Hi Friends,
I need to calculate current Quarter of the Fiscal Year 4 , 5 like that. SAP has Provided 3 Variable(Current Quarter of the Fiscal Year 2 like that 3 variables), my customer is looking for some more variables. Can any one help me out hhow to Calculte Current Quarter of the Fiscal Year 4. How can i see the code of the SAP EXit's. Based on that i will try to write the code.
Thanks in Advance!
Nagesh.Hi Nagesh,
the code for SAP Exits must be in Function-Pools SAPLRS_BCT* (I'm not quite sure). But this code
seems to work different than customer Exits.
See How-To-Guide
https://service.sap.com/~sapdownload/011000358700002762582003E/HowToDeriveVariableValue.pdf
for a good example of how to implement Customer-Extis.
(It's a 2.x Guide but still valid for 3.x)
Regards
Robert -
Predicate boolean method...calculating whether or not a year is a Leap year
I'm trying to get pointed in the right direction for this program. I am attempting to write a program that calculates whether or not an inputted year by the user is a valid leap year or not, however I'm having problems figuring out the method for this calculation.
A predicate method boolean seems to be the right way, but I can't figure out exactly how. Here's what I've brainstormed thus far:
Leap Year Conditions:
1. Is divisible by 4.
2. Is NOT divisible by 100.
3. Is divisible by 4.
public class Year
public boolean isLeapYear()
}What confuses me is how to satisfy these conditions. Here is what I want to fill those '...' with. Excuse the tacky language coming up, but it's the only way I can express my thinking here:
return ((inputted year) / 4) && (inputted year / 400) && !((inputted year) / 100)
If the year is undivisible by any of these values then it could end up being a technical decimal (which means the inputtted year is not a leap year). But of course java would still calculate it anyway depending on how I defined the type.
Should I try to implement a condition that if the variable returned by any of these calculations (except for 100) is a float point then the year is not a leap year? How would I do this?
I'm really not sure where to go on this one. If anyone could point me in the right direction and give me a good start I would appreciate it. Thank you.
Message was edited by:
fairtex
Message was edited by:
fairtexhttp://en.wikipedia.org/wiki/Leap_year
They have some leap year algorithms on there. -
Hi experts,
I need to create a request where I calculate year_todate costs for the previous year (one year ago)
Let's say I have the following figures for 2000:
year________Month_________Day______Acutal Coasts
2000________Jan___________1____________10
2000________Jan___________2____________20
2000________Jan___________3____________30
I used the AGO function to retrieve the previous year costs so I end up with the following request:
year________Month_________Day______Acutal Coasts_____Previous year costs
2001________Jan___________1____________5_________10
2001________Jan___________2____________6_________20
2001________Jan___________3____________7_________30
And to calculate the year_todate costs and I tried OBIEE to_date fucntion :TO_DATE(Previous year costs) , the results was:
year________Month_________Day______Acutal Coasts_____Previous year costs
2001________Jan___________1____________5_________10
2001________Jan___________2____________6_________30(10+20)
2001________Jan___________3____________7_________60(10+20+30)
When I look at the results at Month level
year________Month______Acutal Coasts_____Previous year costs
2001________Jan____________5_________100 (10+30+60)
It's summing up all the coasts at day level and I only need the last value of a month, or a year if I want to display the results at year level.
I also tried to use the RSUM function, but because it's only a display function when I filter on a day (for example day 2 JAN) I only got the results without any running sum:
2001________Jan___________2____________6_________20 (because I exculed the other days with the filter)
Any ideas how I achieve this:
year________Month______Acutal Coasts_____Previous year costs
2001________Jan____________5___________60 when I look at the month level
and
2001________Jan___________2____________6_________30 when I look at the day level.
RegardsThanks venkat for the answer.
It's only solving the problem at month level
year________Month______Acutal Coasts_____Previous year costs
2001________Jan____________5___________60 when I look at the month level
but at day level it's just repeating the value at month level for every day
year________Month_________Day______Acutal Coasts_____Previous year costs
2001________Jan___________1____________5_________60
2001________Jan___________2____________6_________60
2001________Jan___________3____________7_________60
and I want to have the following if I filter on 1JAN and 3JAN
year________Month_________Day______Acutal Coasts_____Previous year costs
*2001________Jan___________2____________6_________30(10+20)*
Regards -
Last Year MTD/YTD Column Without Using Time Series Function
I need to calculate MTD and YTD of last year without using time series function.
My requirement is like:
We are working on Fiscal year.
Suppose user will select a date: 15-Jan-2013Use a period table with Period Ago attributes and join these to an alias of your fact table. In other words, use a period table (let's say Day is grain) that would have
WAgo, QAgo, YAgo, (etc.) attributes for each day. Join this table to aliases of the fact tables on these columns.
Thanks.
Maybe you are looking for
-
Are there any 3rd Party metric tools that does metrics on who access pages?
Hello Gurus, Are there any 3rd Party metric tools that does metrics on who access iviews? I am inquiring on a tool that we can determine how useful the iview(s) to the users community. I understand that SAP has an ADC project. But we are also intere
-
Larger thumbnails in Brushes, Symbols, etc.
The thumbs in the Brushes Panel and the Symbols Panel are still tiny. How are we supposed to see what we're picking? I wish we could make them larger as we can with Color Swatches.
-
Can not Accept and save SERVICE ENTRY SHEET
Hi I have maintained a simple Service master, maintained the conditions in ML33, created a PO. I am doing a Service Entry Sheet, and trying to Accept and save. A popup comes, and if I see ERROR Log it says.. "Z1 001 Needed approval
-
Talking Head Video - Video Masking
I'm using Final Cut Express 1.0. I would like to isolate video in the foreground of some footage that I shot from the video in the background. More specifically, I would like to make the backgound totally transparent, leaving only the foreground vide
-
Ios8 update: cannot add calendar entries via phone
Since updating to ios8, I can no longer add calendar events to my phone. I have always used my outlook.com account for email/cal/contacts with no problems, but now I cannot use the calendar very effectively! I can only add events online, and then th