Calculate quarters in a year??
We have a publication that is sent out to members once a
quarter. What I
would like to do is tell them (when they register online)
when that
publication will start, so, for example if they sign up in
January, how can
I calculate the beginning of the next quarter, which would be
April???
That worked perfectly, thanks for the suggestion.
"Ian Skinner" <[email protected]> wrote in message
news:fno1d8$qaq$[email protected]..
> Steve Grosz wrote:
>> We have a publication that is sent out to members
once a quarter. What I
>> would like to do is tell them (when they register
online) when that
>> publication will start, so, for example if they sign
up in January, how
>> can I calculate the beginning of the next quarter,
which would be
>> April???
>
> The first function I would look at is the
dateAdd('q',1,lastQrtDate).
>
> datepart String:
> yyyy: Year
> q: Quarter
> m: Month
> ...
>
>
Similar Messages
-
How to calculate YTD and Last year YTD on Date in Bex
Hi,
I have a requirement in which I need to show the report as following format.
I need to show Year>monthday as Hierarchy. user will drill down on Month to Date.
Del Qty Ord Qty Del Qty LY Del Qty YTD Del Qty L YTD
Year
> Drill Down to Months
Jan
Feb
Mar
---> 1.03.2010
---> 2.03.2010
---> 3.03.2010
Dec
I have Calday, Calmonth, Calyear all three objects.
Now my question is how I can achive this? On which i need to create hierarchy?
and how to calculate the YTD at day level.
Note:- in the selection calyear is mandatory. User wants to display as per year. So What infoobject I need to take in selection?
and the way to calculate YTD on Day (in the case also ,where user doesn't give the date in selection)
Plz reply asap its uregent !!!
Thanks in advance,
AmitHi,
As per my understanding I think YTD means JAN to current date result. I means say if user enter 062005 then result in YTD should be from 012005 to 062005.
And to do this you need to write a customer exit variable where LOW field of internal table you will put JAN year and HIGH will contain month year entered by user.
Hope this will help you.
Suneel -
Hello Good Evening,
Could you please help me here
how to write condition for self table year records, such 2012 name and acctno match with 2013 name and acctno then total, provided below,
create table #tab1 (MasterKey int, AcctNo varchar(12),name varchar(25), SumaofShares numeric, request_dat datetime )
--drop table #tab1
insert into #tab1 values (1000, 100,'Tom', 2500, '10/01/2012')
insert into #tab1 values (1001, 101,'Bat', 1550, '08/11/2012')
insert into #tab1 values (1002, 102,'Kit', 1600, '06/12/2012')
insert into #tab1 values (1003, 103,'Vat', 1750, '04/15/2012')
insert into #tab1 values (1010, 104,'Sim',200, '04/21/2013')
insert into #tab1 values (1011, 105,'Tim',500, '06/18/2013')
insert into #tab1 values (1012, 100,'Tom',800, '08/22/2013')
insert into #tab1 values (1013, 101,'Bat',550, '09/15/2013')
insert into #tab1 values (1014, 100,'Pet',200, '02/21/2013')
insert into #tab1 values (1015, 103,'Vat',150, '03/18/2013')
insert into #tab1 values (1016, 110,'Sun',800, '03/22/2013')
insert into #tab1 values (1017, 111,'Bet',550, '12/15/2013')
insert into #tab1 values (9999, 111,'AAA',110, '12/15/2014')
create table #tab2 (IssueKey int, totalOutstanding numeric, sharedBenefits varchar(1) )
--drop table #tab2
insert into #tab1 values (1000, 500, 'V')
insert into #tab1 values (1001, 150, 'U')
insert into #tab1 values (1002, 100, 'N')
insert into #tab1 values (1003, 170, 'U')
insert into #tab1 values (1010, 100, 'U')
insert into #tab1 values (1011, 200, 'K')
insert into #tab1 values (1012, 340, 'U')
insert into #tab1 values (1013, 560, 'N')
insert into #tab1 values (1014, 280, 'V')
insert into #tab1 values (1015, 150, 'V')
insert into #tab1 values (1016, 840, 'V')
insert into #tab1 values (1017, 530, 'N')
i would like to get 4 columns output
how to get sumofshares (#tab1) and TotalOutStanding(#tab2) summ up with these values please.,
MasterKey (#tab1) and IssueKey (#tab2) are like primary key and foreign key
so the request is
need to calculate, sumofshares (#tab1) and TotalOutStanding(#tab2) as below
1)ShareBenefist = U and year( request_dat) in (2012 , 2103) and (Name for 2012 should match with 2013 name and 2012 Acctno should match with 2013 accounno) in (#tab1)
then '2012 and 2013 accts UN Veriverted'
2)ShareBenefist = V and year( request_dat) in (2012 , 2103) and (Name for 2012 should match with 2013 name and 2012 Acctno should match with 2013 accounno) in (#tab1)
then '2012 and 2013 accts Veriverted'
3)ShareBenefist = N and year( request_dat) in (2012 , 2103) and (Name for 2012 should match with 2013 name and 2012 Acctno should match with 2013 accounno) in (#tab1)
then '2012 and 2013 accts NONVERT'
4)year( request_dat) =2102 and Name and Acctno not match with 2013 account name and acctno (#tab1)
then '2012 last year accounts'
5)year( request_dat) = 2013 and Name and Acctno not match with 2013 account name and acctno (#tab1)
then '2012 This year accounts'
for ex 1) the below accounts in #tab1 has both 2012 and 2013 and acctno same in both years and name is same in both years so it is condired as
insert into #tab1 values (1012, 100,'Tom',800, '08/22/2013')
for ex 2)
insert into #tab1 values (1013, 101,'Bat',550, '09/15/2013')
for ex 4) 2012 records there is not match acctno and name in 2013 recods
insert into #tab1 values (1002, 102,'Kit', 1600, '06/12/2012')
for ex 5) 2013 records there is no match of name and acct no with 2012 records
insert into #tab1 values (1010, 104,'Sim',200, '04/21/2013')
insert into #tab1 values (1014, 100,'Pet',200, '02/21/2013')
insert into #tab1 values (1016, 110,'Sun',800, '03/22/2013')
insert into #tab1 values (1017, 111,'Bet',550, '12/15/2013')
Expected Results (just for format)
AcctTypeDescription, SumofShares, OtotalutStand
'2012 and 2013 accts UN Veriverted',2700,234
'2012 and 2013 accts Veriverted' ,2890,234
'2012 and 2013 accts NONVERT' ,4533,325
'2012 last year accounts' ,2334,567
'2012 This year accounts' ,2222,877
Please
Thank youy in advance
asitaAs I understand it, your sample output was only to show the format, and did not pretend to be give the exact result given the sample data. This is pity, because means that I was not able to verify that my query below gives the desired result.
The exact relation between #tab1 and #tab2 is not clear to me. I'm making the assumption that a row in #tab1 may have zero or one row in #tab2, but not many.
My solution has two CTEs. The first simply joins the tables together and extracts the year. In the second CTE, I perform a self-join over the first CTE which I have divided in two by year. This is a full join, since an account may appear for only one of
the year. Note that it is instrumental to extract the year data in inner queries first.
The final query is just an aggregation over the categories.
create table #tab1 (MasterKey int, AcctNo varchar(12),name varchar(25), SumaofShares numeric, request_dat datetime )
--drop table #tab1
insert into #tab1 values (1000, 100,'Tom', 2500, '10/01/2012')
insert into #tab1 values (1001, 101,'Bat', 1550, '08/11/2012')
insert into #tab1 values (1002, 102,'Kit', 1600, '06/12/2012')
insert into #tab1 values (1003, 103,'Vat', 1750, '04/15/2012')
insert into #tab1 values (1010, 104,'Sim',200, '04/21/2013')
insert into #tab1 values (1011, 105,'Tim',500, '06/18/2013')
insert into #tab1 values (1012, 100,'Tom',800, '08/22/2013')
insert into #tab1 values (1013, 101,'Bat',550, '09/15/2013')
insert into #tab1 values (1014, 100,'Pet',200, '02/21/2013')
insert into #tab1 values (1015, 103,'Vat',150, '03/18/2013')
insert into #tab1 values (1016, 110,'Sun',800, '03/22/2013')
insert into #tab1 values (1017, 111,'Bet',550, '12/15/2013')
insert into #tab1 values (9999, 111,'AAA',110, '12/15/2014')
create table #tab2 (IssueKey int, totalOutstanding numeric, sharedBenefits varchar(1) )
--drop table #tab2
insert into #tab2 values (1000, 500, 'V')
insert into #tab2 values (1001, 150, 'U')
insert into #tab2 values (1002, 100, 'N')
insert into #tab2 values (1003, 170, 'U')
insert into #tab2 values (1010, 100, 'U')
insert into #tab2 values (1011, 200, 'K')
insert into #tab2 values (1012, 340, 'U')
insert into #tab2 values (1013, 560, 'N')
insert into #tab2 values (1014, 280, 'V')
insert into #tab2 values (1015, 150, 'V')
insert into #tab2 values (1016, 840, 'V')
insert into #tab2 values (1017, 530, 'N')
go
WITH joined AS (
SELECT a.MasterKey, a.AcctNo, a.name, a.SumaofShares,
year(a.request_dat) AS year, b.totalOutstanding, b.sharedBenefits
FROM #tab1 a
LEFT JOIN #tab2 b ON a.MasterKey = b.IssueKey
), categories (category, sumofshares, totaloutstanding) AS (
SELECT CASE WHEN A.MasterKey IS NOT NULL AND
B.MasterKey IS NOT NULL
THEN '2012 and 2013 accts ' +
CASE B.sharedBenefits
WHEN 'U' THEN 'UN Veriverted'
WHEN 'V' THEN 'Veriverted'
WHEN 'N' THEN 'NONVERTED'
ELSE ''
END
WHEN A.MasterKey IS NOT NULL THEN '2012 last year accounts'
WHEN B.MasterKey IS NOT NULL THEN '2013 this year accounts'
END,
coalesce(A.SumaofShares, 0) + coalesce(B.SumaofShares, 0),
coalesce(A.totalOutstanding, 0) + coalesce(B.totalOutstanding, 0)
FROM (SELECT * FROM joined WHERE year = 2012) AS A
FULL JOIN (SELECT * FROM joined WHERE year = 2013) AS B
ON A.AcctNo = B.AcctNo
AND A.name = B.name
SELECT category, SUM(sumofshares) AS sumofshares,
SUM(totaloutstanding) AS totaloutstanding
FROM categories
GROUP BY category
go
drop table #tab1, #tab2
Erland Sommarskog, SQL Server MVP, [email protected] -
How to restrict prevmember function to calculate for a particular year
Hi,
I have a MDX query that calculates the cumulative sum, using current & previous member. Now when year is January, i want the query to ignore prevmember value. Can somebody please help how this can be achieved?
My query:
CASE WHEN
[Date].[CALENDAR].PrevMember
,[Measures].[TOTAL KM]
) + [Measures].[TOTAL KM] )=0 THEN 0
ELSE
[Date].[CALENDAR].PrevMember
,[Measures].[Number of Events]
) + [Measures].[Number of Events]) * 200000/
[Date].[CALENDAR].PrevMember
,[Measures].[TOTAL KM]
) + [Measures].[TOTAL KM] ) ENDHi Mayank,
According to your description, you need to calculate the cumulative sum, and reset it on January of each year, right?
In this case, you can use YTD function to achieve your requirement. I have tested it on AdventureWorks, the query below is for you refernece.
WITH MEMBER MEASURES.YTDDEMO AS
AGGREGATE(YTD(), [Measures].[Internet Sales Amount])
SELECT {[Measures].[Internet Sales Amount], MEASURES.YTDDEMO} ON 0,
[Date].[Calendar].[Month].MEMBERS ON 1
FROM
[Adventure Works]
Regards,
Charlie Liao
TechNet Community Support -
Calculate different month and year
Dear experts,
Hereby, i have 2 questions:
1)Are any data type for month and year format (YYYYMM)? Generally, we have the data type for date which is 'D', but it is in YYYYMMDD format. Currently, i define the data type as length 6 type c.
2) Does SAP function module have functions to calculate the different month? For example: 11.2009 - 01.2010 = 2
Because currently, i define the type as length 6 type c, thus, the calculation for this difference are quite tedious. Or does anyone have any sample for this type of function?
Thanks in advance.Hi, Starry
Please Search in SCN or Google, Date Related Question are not allowed. Check the bellow Thread for more info.
How to post code in SCN, and some things NOT to do...
Regards,
Fasial -
User exit to calculate Same period Last Year
Dear gurus,
can some help me to code the user exit to calculate the same period last year for bex variable
i.e
System date :18.05.2010
Same period last tear : 18.05.2009
Your help highly appreciated
Thank you
BRHi,
The above code creates problem only when date is 29th of Feb.
To find whether year -1 is leap yr or not include following code also:
l_year = sy-datum(4)-1 .
l_mod4 = l_year mod 4.
l_mod100 = l_year mod 100.
l_mod400 = l_year mod 400.
if ( l_mod4 = 0 and l_mod100 ne 0 ) or l_mod400 eq 0.
if( l_date = 29)
l_date= l_date -1.
endif.
endif.
Modify your code according to youe need. Hope this helps you.
Thanks,
Jitender. -
Query - to calculate data for previous year
Hi forum,
I have a requirement to calculate
' Total number of complaints received current month last year / total number of complaints last year)*current year total complaints target.'
I have no of complaints as key figure.
Any ideas how to do it in query designer.
Thanks in advance.
Regards,Hi,
The requirement is user will select the month he wants to see the records.
Based on input I have to calculate
1. Records from same month previous year.
2. Total records last year and
3. Total records this year.
I just need 1 input variable. Please explain in detail.
Should i create 2 RKF for records of previous year and for records of this year.
regards -
guru's,
the yearly report for production should be displayed in quarters and the quarters should be in roman format.is there any possiblity of making this successful with routine or any other method ??
this is an urgent requirement plz send in your answers.
thank you.Yes, it is very much possible.
What I know is:
Create a new InfoObject for CALQUARTER with datatype char and length 3.
Now in the update rules use the formula
IF( ( RIGHT( 2, LEFT( 6, Calendar day ) ) >= 1 AND RIGHT( 2, LEFT( 6, Calendar day ) ) <= 3 ), 'I', IF( ( RIGHT( 2, LEFT( 6, Calendar day ) ) >= 4 AND RIGHT( 2, LEFT( 6, Calendar day ) ) <= 6 ), 'II', IF( ( RIGHT( 2, LEFT( 6, Calendar day ) ) >= 7 AND RIGHT( 2, LEFT( 6, Calendar day ) ) <= 9 ), 'III', IF( ( RIGHT( 2, LEFT( 6, Calendar day ) ) >= 10 AND RIGHT( 2, LEFT( 6, Calendar day ) ) <= 12 ), 'IV', 'V' ) ) ) )
But my formula is based on Calday...I hope you must be having a Day field-Calday or Posting date in your Communication structure.
This one has worked for me.
Try and revert soon.
Regards
Gajendra -
How calculate Quarters without 0CALQUARTER
Hi Gurus!,
i got the next problem: i must create a query with some key figures calculated by quarters, exactly the indicator is how much is the difference between quarter 2. 2011 and 1.2011 for example, but in the cube is loaded many years of data without the IO 0CALQUARTER loaded, now i dont know, if exist some way to simulate this calculation with 0FISCPER in the query designer, this IO has been loaded all the time, i will appreciate your help gurus.hi,
you can write an abap code that converts 0fiscper into quarters, so that it can act itself as a 0CALQUARTER.
for example for the fiscper(4)+3= 1 or 2 or 3 , the result field for calquarter(say our variable) can be depicted as one quarter and similarly you can write conditions for other quarters.
hope this will solve your problem
regards
laksh -
Dynamic Calc Member with Formula to Calculate a Rolling 13 Year
I have to create a rollup in my time dimension that will have 13 members representing each month of a 13 rolling forecast. I am having trouble setting this up as dynamic calc members with a formula assigned to it. For example, on of the members has the following formula.
As you can see, I am referencing several substitution variables since I want to make this as most dynamic as possible without having to make any changes to the formula member. Only making changes to the substitution variable. Any help would be much appreciated.
IF((@ISMBR(&Current_Year)) AND (&Act_RF_Last_Month == "Jan"));
"RTM 6" = @MDSHIFT(&Act_RF_Last_Month, -1, "Years", , 5, "Period",);
ELSE #Missing;
ENDIF
IF((@ISMBR(&Current_Year)) AND (&Act_RF_Last_Month == "Feb"));
"RTM 6" = @MDSHIFT(&Act_RF_Last_Month, -1, "Years", , 5, "Period",);
ELSE #Missing;
ENDIF
IF((@ISMBR(&Current_Year)) AND (&Act_RF_Last_Month == "Mar"));
"RTM 6" = @MDSHIFT(&Act_RF_Last_Month, -1, "Years", , 5, "Period",);
ELSE #Missing;
ENDIF
IF((@ISMBR(&Current_Year)) AND (&Act_RF_Last_Month == "Apr"));
"RTM 6" = @MDSHIFT(&Act_RF_Last_Month, -1, "Years", , 5, "Period",);
ELSE #Missing;
ENDIF
IF((@ISMBR(&Current_Year)) AND (&Act_RF_Last_Month == "May"));
"RTM 6" = @MDSHIFT(&Act_RF_Last_Month, -1, "Years", , 5, "Period",);
ELSE #Missing;
ENDIF
IF((@ISMBR(&Current_Year)) AND (&Act_RF_Last_Month == "Jun"));
"RTM 6" = @MDSHIFT(&Act_RF_Last_Month, -1, "Years", , 5, "Period",);
ELSE #Missing;
ENDIF
IF((@ISMBR(&Current_Year)) AND (&Act_RF_Last_Month == "Jul"));
"RTM 6" = @MDSHIFT(&Act_RF_Last_Month, -1, "Years", , 5, "Period",);
ELSE #Missing;
ENDIF
IF((@ISMBR(&Current_Year)) AND (&Act_RF_Last_Month == "Aug"));
"RTM 6" = @SHIFT(&Act_RF_Last_Month,-7);
ELSE #Missing;
ENDIF
IF((@ISMBR(&Current_Year)) AND (&Act_RF_Last_Month == "Sep"));
"RTM 6" = @SHIFT(&Act_RF_Last_Month,-7);
ELSE #Missing;
ENDIF
IF((@ISMBR(&Current_Year)) AND (&Act_RF_Last_Month == "Oct"));
"RTM 6" = @SHIFT(&Act_RF_Last_Month,-7);
ELSE #Missing;
ENDIF
IF((@ISMBR(&Current_Year)) AND (&Act_RF_Last_Month == "Nov"));
"RTM 6" = @SHIFT(&Act_RF_Last_Month,-7);
ELSE #Missing;
ENDIF
IF((@ISMBR(&Current_Year)) AND (&Act_RF_Last_Month == "Dec"));
"RTM 6" = @SHIFT(&Act_RF_Last_Month,-7);
ELSE #Missing;
ENDIFWe use similar logic but its in a calc script, not a dynamic formula.
Here's an example of what we do:
FIX (&Year, &Scenario)
IF (@ISMBR("JAN"))
"Average Usage%" = @AVG(SKIPBOTH, @MDSHIFT("Usage %"->"DEC"->&actYear, -1, "Year",), "Util %"->"JAN"->&actYear);
ELSEIF
ENDFIX
Another example in a different database:
IF (@ISMBR("JAN")) ((@MDSHIFT("Fees"->APR,-1,YEARS,)+@MDSHIFT("Fees"->MAY,-1,YEARS,)+@MDSHIFT("Fees"->JUN,-1,YEARS,)+@MDSHIFT("Fees"->JUL,-1,YEARS,)+@MDSHIFT("Fees"->AUG,-1,YEARS,)+@MDSHIFT("Fees"->SEP,-1,YEARS,)+@MDSHIFT("Fees"->OCT,-1,YEARS,)+@MDSHIFT("Fees"->NOV,-1,YEARS,)+@MDSHIFT("Fees"->DEC,-1,YEARS,)+"Fees"->JAN)/10)*12; -
MDX - Average of months values for quarters, semesters and years
Hello,
I would like to aggregate month values in MDX query to get quarter, semester and year ones.
The problem is that "SUM" is used by default, but I want the "average" for quarter, semester and year values.
Example (AVG columns are expected, not SUM ones) :
Year
Month
Value
sum Q
avg Q
sum S
avg S
sum Y
avg Y
2011
1
130,71
416,58
138,86
843,66
140,61
1499,33
136,30
2011
2
146,71
2011
3
139,15
2011
4
133,51
427,08
142,36
2011
5
147,14
2011
6
146,43
2011
7
128,58
373,59
124,53
655,67
131,13
2011
8
109,98
2011
9
135,03
2011
10
135,83
282,09
141,04
2011
11
146,27
2011
12
NULL
Thanks for help.Hi Unkedeuxke,
As Ken said, we do not have a measure Average aggregation type in SQL Server Analysis Services. We do have AverageOfChildren (or Average over time), however it is semi-additive and works only along a Time dimension. Fortunately, we have Sum and Count, and
since Average = Sum / Count, we can build our own Average aggregation when we need one. Here is a blog about how to create a average measure, please refer to the link below.
Average Aggregation in Analysis Services
Regards,
Charlie Liao
TechNet Community Support -
How to calculate Average No. Of Years
Hi Experts,
I want to show the data of 'Average years spent by employees in a position'.I ahve the following data : Position, Employee, Valid From and Valid to as Characteristics and no key figures. With this data, I need to show something like this :
<u>Position</u> <u>AvgNo.OfYears</u>
Position1 - 5
Position2 - 3.5
The no. of years is calculated by the formula variable using the valid from and To characterisitics for each employee.
I can get the average using aggregation in the result line . But all the employee names appear along with each position.i.e, if there have been 100 employees till date who have completed Position1, all of them will be displayed. I don't want to show the employees but just the position and the Average no. of years.
If i hide the employees, only the text is not displayed -but there will be 100 vacant lines shown against 1 position (i.e, the no of employees).
I am taking all the data from a DSO. I cannot create a new inforobject either due to some restrictions. Kindly help.
Regards,
Rekhasorry i was away for several days...
did you find a solution? I had really the same issue in the past and had no issues with using multiple formula variables. When you say "it doesn't work" what do you mean?
In the past I have done this:
Material Attribute - Numerator --> Formula var - Num
Material Attribute - Denominator --> Formula var - Denom
Misc Attribute - Anything Numeric --> Formula Var - X
CKF --> (Num/Denom) *(X/X)
without the (X/X) the results would only be accurate if the detail characteristic was displayed in the rows. With X/X the calculation worked at any level.
I did the same logic for different cubes and data types including Sales, Inventory, Production Control, etc -
Hi Experts,
I need to calculate the age in years. I have the date of birth already in my infoprovider that iam using for my query.
The user will be entering the date on which he want to calculate the age in the selection screen and the date will be stored in a variable..
Now how to calculate the age in years and display it as a separate coloumn in the report?
Regards,
KhanHi,
Here 1st create the one formula variable on birth date
then create one more formul variable customer exit varaible with user entry here u cna use the i_step = 2 there user enters which ever that date based on that date it executes
in CKF: this customer exit user entry varible - birth date formula varible
whenever the user enters date based on that now u r getting days of the employe AGe
now that CKF can be used in another CKF by using age/365
now in report u can keep only second CKF.
Thanks & Regards,
Sathish -
How to calculate year and month
Dear Friends
I have to make a customised report.In this report there are different buckets of one year from the year and month being entered by the user.
For example if user is giving input value for year and month as 200912 then system has to show data in first bucket for the period 200912 to 200901.In the second bucket system will show data for period 200812 to 200801.In this way system has to show data in 11 buckets for 11 years.
Is there any function module/BAPI in SAP through which system will calculate period of one year for different buckets for my report from the input value(year and month) being given by the user.
Moderator message - Please see The specified item was not found. before posting - post locked and Points unassigned
Edited by: Rob Burbank on Jan 5, 2010 11:03 AMHi Satish,
You can do this with a Standard function module.
I am providing my code below :
data : G_date type sy-datum.
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
DATE = sy-datum " instead of sy-datum provide
" the select option here which user provides.
DAYS = C_fourty"45
MONTHS = C_MM "00
SIGNUM = C_Negative "'-'
YEARS = C_YY "00
IMPORTING
CALC_DATE = G_date. "G_date will have date less than 45 days
* " from the day program has been executed.
Now based upon the G_DATE, we can fetch remaining 10 buckets.
Regards,
Kittu
Edited by: Rob Burbank on Jan 5, 2010 11:01 AM -
SSAS DAX formula for same period last year not same month last year
The DAX function sameperiodlastyear, only works if the period we are interested in, is the same as a month.
However our Period 3 for 2014 was 05-march to 04-April and Period 3 in 2013 was 01-March to 31-March
I have a dim_Date table with a separate Year Number and Period Number so you be able to match on Period Number and Year - 1
The sort of formula I am after is this, so that the P3 total for 2013 matches the value reported as 'PY' against P3 2014
so for example
PY:=calculate(sum(amount), dim_date(year) = dim_date(year-1) && dim_date(period) = dim_date(period)
I cannot find an exact example of how to construct the DAX formula to achieve this.
I have tried DAXPatterns.com, but that does not have an exact example.
Thanks in advance
SotnAll built-in time intelligence functions work on the standard Gregorian calendar. The only fiscal calendars that can be handled by the built-in functions are those that end on another day than December 31, but otherwise respect the standard months/quarters.
The problem you are encountering in your [PY] is that CALCULATE() only allows simple boolean predicates (no calculations allowed. FILTER() is the function that allows you to execute arbitrary logic in your CALCULATE() filter arguments.
Try this:
PY:=
CALCULATE(
SUM( <fact table>[amount] )
, FILTER(
ALL( dim_date )
, dim_date[year] = MAX( dim_date[year] ) - 1
&& dim_date[period] = MAX( dim_date[period] )
Here's what's going on in that FILTER(). FILTER() is an iterator - it steps row-by-row through the table that you pass as the first argument, and returns only those rows that meet the criterion you set in the second argument.
We pass ALL( dim_date ). This strips the current filter context from the pivot table and returns every row of dim_date.
In the second argument to FILTER() we define the logic that will determine which rows to return. This comes in two parts, connected with the logical and operator, &&. I will only explain one in detail as we're using the same pattern in each part.
dim_date[year] is referring to the value of the column [year] based on where you are in the table (remember, FILTER() is stepping row-by-row through), so will return one value from the current row based on FILTER()'s iteration.
It then compares that value to what is returned by MAX( dim_date[year] ) - 1. This expression is not evaluated in the current row context of FILTER(), rather in the filter context of the pivot table (in a pivot table your row and column labels are referred
to as rowfilters and columnfilters - this nomenclature can get confusing). Thus, it returns whatever the current year of the pivot table is and subtracts one. When the value of [year] in dim_date matches the value returned by this expression, that row is part
of the set returned by FILTER().
Once FILTER() has completed its iteration, it returns the filtered table, and that table is used to set the filter context that SUM( <fact table>[amount] ) is evaluated in.
Maybe you are looking for
-
A suggestion for handling optdepends.
[UPDATE] I've rewritten this post to present the idea more clearly. [/UPDATE] I've submitted a feature request: http://bugs.archlinux.org/task/12708 If you like this idea, please express your support there too. The Current Situation The pacman databa
-
Are any user exits or other methods of enhancement available for terms of payment? My customer has vendor terms of payment that cannot be configured using the standard configuration parameters. Examples of these are: 1) Anticipation: Assuming an annu
-
Hi, Have been using iTunes 10.5 on my WinXP machine - no problems. During a movie download tonight, iTunes crashed. Tried to reopen and got the infamous error "iTunes Library file locked or on a locked disk..." Tried several remedies listed. Veri
-
Will mountain lion support microsoft word
How do I get my documents from Microsoft word? I have them backed up.
-
JDev ADF Faces and XML publisher integration
Hi, I have an ADF Faces / BC project which I want to integrate XML Publisher for reporting and output purposes. Following this note by Deepak Vohra http://www.oracle.com/technology/pub/articles/vohra-jdev-xmlpub.html (which was incredibly helpful by