I am using excel 2013 powerpivot which I have linked to a sql query. In this query I have all sales data from previous years and it updates itself with the current sales. I want to make a pivottable showing year to date sales from this year compared to the same period last year. So for example from Jan.1st 2015 until July 10th of 2015 compared to Jan.1st 2014 until July 10th 2014.
I linked my sales data table with a calendar table. But whatever I try, parallelperiod, sameperiodlastyear, totalytd, it always shows me the correct data for this year, but the full year sales of last year. Can anyone recommend me what to try?
thanks,
Frank
The TOTALYTD (and other time intelligence functions) will look for the highest date in whichever context you give it, so when you try to tell it to go back 12 months from now it thinks "OK, I'm in 2014" I'll get ALL the data from 2014 and calculate a TOTALYTD. So you have to ignore the built-in functions and build your own:
=CALCULATE(sum(Table1[sales]),DATESBETWEEN(DateDim[Date], FIRSTDATE(DATEADD(DateDim[Date],-12,MONTH)), LASTDATE(DATEADD(Table1[Date],-12,MONTH))))
So long as you have a slicer or a field on your table that picks up the year, then that should work.
Edit: Having tested with a data sample, again DAX is trying to be too clever and because I have told it to go back 12 MONTHS, it assumes I want ALL data from the month context which is including everything from July last year.
Going back 365 days fixes this (as long as it's not a problem for leap years).
=CALCULATE(sum(Table1[sales]),DATESBETWEEN(DateDim[Date], FIRSTDATE(DATEADD(DateDim[Date],-12,MONTH)), LASTDATE(DATEADD(Table1[Date],-365,DAY))))
I have tried your way, but it does not yet give me the correct answer. Let me show you what I have right now.
For current year sale I have the following Dax formula
=TOTALYTD(sum(Omzetgegevens[NettoOmzet]); Kalender[Calender date])
For the previous year sale I have:
=CALCULATE((SUM(Omzetgegevens[NettoOmzet])); SAMEPERIODLASTYEAR(DATESYTD(Kalender[Calender date])))
To test your solution I have called "test ytd":
=CALCULATE(SUM(Omzetgegevens[NettoOmzet]); DATESBETWEEN(Kalender[Calender date]; FIRSTDATE(DATEADD(Kalender[Calender date];-12; MONTH)); LASTDATE(DATEADD(Kalender[Calender date]; -365; DAY))))
If I run the pivottable now, the result I get is:
2015
current year ytd last year ytd test ytd
januari 28.912 34.487 34.487
februari 50.301 66.003 31.516
maart 73.362 92.647 26.644
april 99.561 117.853 25.205
mei 128.021 149.108 31.255
juni 149.706 174.076 24.968
juli 158.297 205.438 31.362
augustus 158.297 231.693 26.255
september 158.297 254.534 22.841
oktober 158.297 282.484 27.951
november 158.297 303.808 21.324
december 158.297 313.208 9.400
Total 158.297 313.208 313.208
What I would like to see is the following. As this report was run on the 14th of july 2015. I want to see all sales for 2015 until this date and all the sales for 2014 until july 14th 2014.
If it is not possible to see the months, I am also fine with only a total number for current ytd and last year ytd
2015
current year ytd last year ytd
januari 28.912 34.487
februari 50.301 66.003
maart 73.362 92.647
april 99.561 117.853
mei 128.021 149.108
juni 149.706 174.076
juli 158.297 175.312(so not full month of july in 2014)
Total 158.297 175.312
Recently had a similar issue. Current context confuse a lot and did not return the result we think should be returned. Play with DATEADD to go back and forth in combination with any of the date/time function. You will get the result and the context will also be clear.
Related
I am trying to create a month and year to date column but the FY starts from October and I need it to roll into the next year so this can automatically update in Power Bi I have the Date ID for our year now maybe need flags to show the current month and current year then I can create a measure in Power Bi, also need it to sum up the months for year to date etc if I click january it shows me sales from October to January.
How can I build a DAX function which calculates all the data until a certain date and compare that with the previous year which have the same months as the "until" date?
For example, today's date is 5 April 2018, so if I select 2017 year inside the slicer, I should be able to see a graph which shows me the comparison between the start of year i.e 1 Jan 2018 to 5 April 2018, and 1 Jan 2017 to 5 April 2017 with the previous year.
Currently I am using YtD, but I think it's calculating all the 12 months of data of all the years except the year 2018, where it shows me data from Jan 1 to April 5. Can anyone shed some light here?
Currently I am using this YTDQty = TOTALYTD(sum(Bookscan[QtySold]),DATESYTD(Bookscan[Week Date]))
Which is showing me correct data of 2018, till date, I should be able to compare the 4 months of data to my previous years 2017, 2016, 2015, these years are showing me total data for all the years i.e 12months of data, However I only need to see data start from 2018 Jan till todays date or let say March 1, so all the years should show me this current data how to do this?
Very similar to this question.
Do you have a Date Dimension in your model?
TotalQuantity =
SUM(Bookscan[QtySold])
TotalQuantity YTD =
TOTALYTD([TotalQuantity],'Date'[Date])
TotalQuantity YTD LY =
CALCULATE(
[TotalQuantity YTD],
SAMEPERIODLASTYEAR('Date'[Date])
)
I have two files, one with event date, the other one is the security prices I need to match the month with event month 0, -1 (previous month), and +1 (the month after event month). So e.g., one observation has event date 1/1/2010, I have the daily bond prices from 1/1/2009 to 1/20/2010, but I need to match January,2010 to December 2009 prices and February 2010. I have the following codes to do that,
PROC SQL;
CREATE TABLE test AS
select *
FROM bondprice as a, sdc as b
where b.Participant_CUSIP=a.cusip
& INTCK('MONTH',b.Alliance_Date,a.time)>=-1
& INTCK('MONTH',b.Alliance_Date,a.time)<=1 ;
QUIT;
DATA test1;
SET test;
BY deal_number CUSIP code time;
IF first.code THEN price1=price;
IF first.code THEN day1=time;
IF last.code THEN price0=price;
IF last.code THEN day0=time;
RUN;
clearly this observation should be only matched in 1-month Jan 2010 (0,0) and 2-month Dec 2009 to Jan 2010 (-1,0), because it does not have 3-month Feb 2010's prices. However, if using my codes above, it will yield as a valid obs who has 3-month price since it fell into the range of >=-1 and <=1.
So the first part of code is not accurate (the >= and <= range): it yields any prices that falls into December 2009 to Feb 2010, this is wrong because of two situations. First, if the bond prices stops in between Dec 2009 and Jan 2010, it will be counting as a valid 2-month and 3-month observations. Second, if the bond prices begins in between Jan 2010 and Feb 2010, it will be counting as a valid 3-month observation. Both of these two situation will yield invalid observations, since the first situation do not have Feb 2010 prices but still counts as 2-month and 3-month, and the second situation do not have either Dec 2009 or Jan 2010 prices, but still counts as 3-month.
Will someone help me with this? How can I modify the code so that the 3-month window and 2-month window contains the relative months?
I hope I describe the problem clearly. Please let me know if anything is unclear.
I've uploaded an example to this problem here.
https://www.dropbox.com/s/hx9ahst7nts4k0q/ex1.xlsx?dl=0
I have been asked to produce 2 KPI charts which give a Rolling 12 month percentage of:
1.Percentage of hours lost due to long term sickness against hours available
2.Percentage of hours lost due to short term sickness against hours available
As you can see in the image below I have the totals as per the last day of the month up until the day the KPI is viewed. (see as at date) This is saved as a view.
KPI View
Can anybody now help me with displaying the data so that it totals up the hours as per the last 12 months? once I have these the percentages I can do, its the totalling the hours over the rolling 12 months I am struggling with.
e.g
if ran today (23/03/2016)
march 2016 would be the sum of all the results from april 2015 to 23 march 2016
Feb 2016 would be the sum of all the results from march 2015 to 29th feb 2016
and so on...
Thank you in advance.
I would consider window function. For example, generating running total of AvailableHours:
sum(AvailableHours)over(order by calendarshortyearmonth asc) as run_total_AvailableHours
What I am trying to do
I am somewhat desperately trying to build an algorithm which converts financial figures from different companies from fiscal periods to calendar periods.
The problem
Fiscal periods often do not correspond to calendar periods, e.g. a company might report fiscal year 2011 revenues of 100 USD but its fiscal year does not end at the end of December 2011 but instead on September 2011. For instance, Apple's fiscal year ends end of September. Dell's fiscal year ends end of January and Intel's fiscal year ends end of December. For Apple and Dell, all fiscal quarter and fiscal half year ends are shifted as well.
In order to compare revenues or other financial metrics among these companies, I need to be able to convert each fiscal period into equivalent calendar periods. For instance, someone might ask, how much revenue each company generated in calendar year 2011.
In the case of Apple Corp., we would need to remove the revenues which have been generated in calendar period 2010, which would equal Apple's fourth quarter of FY2010 and add the first quarter of fiscal year 2012 (which ended December 2011).
What I have (data model)
My data model has the following attributes for each entity calendarPeriod and fiscalPeriod:
endYear (year in which the period ends)
endMonth (month number
1..12 at which last day the period ends)
length (number of months 1..12 of the period)
What I need (desperately)
What would be the most efficient and short algorithm I could accomplish this?
It would be great if the algorithm could handle "special situations" like Dell where it would need to take 1/3 of its fiscal first quarter, which ends awfully on January, of the following year and adding it to the last quarter of the preceding year. In addition the algorithm should be flexible enough to handle all period lengths and endMonths and try to combine periods if necessary (for instance for the first half of calendar year 2012, it should try to find a six month period which ends June 2012 or consecutively add two periods (one ending March 2012 and one ending June 2012 or taking a fiscal year which ends June 2012 and subtracting the quarters or half year which fall in calendar year 2011).
Thank you so much.
This is more of a financial question then technical question.
If you have end of year results only, there is no practical way you could compare unless they are for same financial period.
Further, if you somehow manage to get the monthly results and do some juggling to prepare comparable results, they will not be comparable as there are many accounting adjustments and provisions generally done in the end of year financial result and not in monthly results which you will miss here.
I would suggest that you should try to compare those results which yields more meaningful results.