Pivot Table adding "2" to value in Report Filter - vba

I have a file with pivot tables where the filter values are updated on a monthly basis based on the last month's date. VBA code for this:
Dim SelectDate As String
SelectDate = Worksheets("Raw").Range("A3").Value
Worksheets("Main").PivotTables("PivotTable4").PivotFields("Date").CurrentPage = SelectDate
The value in cell A3 is string based on the following function:
=A1&" "&A2
For example: January 2017
Updating the pivot tables worked fine for several months, but for this month my values no longer update correctly and after doing some investigation I realized that my pivot table has created two entries in the filter for the month January 2017 and January 20172, while November 2016 went missing:
However, when I check my underlying data, I only have one value for each month:
June 2016
February 2016
March 2016
January 2016
November 2016
December 2016
August 2016
May 2016
October 2016
July 2016
September 2016
April 2016
January 2017
February 2017
Note that when I create an new Pivot table with the same data, the filter only shows January 2017.
Any suggestions why the filter for the existing pivot table would reflect both January 2017 and January 20172?
Thanks for your help!

Here is what worked for me. This happened from what I have read elsewhere either because I added now data lines or because I did a find-and-replace. But then I changed the area of the source data in the pivot table from say
'MASTER (3)'!$A$5:$EQ$600 to 'MASTER (3)'!$A$5:$EQ$6
and then back to
'MASTER (3)'!$A$5:$EQ$600
This resolved the problem

Related

How to build a Dax to view data of all the months till data w.r.t all the years?

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])
)

Sorting Month And Year Results In Microsoft Access

I have the following table in Microsoft Access
TransactionDate
Market
Details
Opening
Closing
Size
Profit/Loss
I want to run a query that shows the Profit/Loss for each month.
I have been able get a query that returns the information in the following format
TransactionDate By Month Sum Of Sum Of Profit/Loss
April 2014 €1,084.99
April 2015 €674.33
April 2016 €2,057.30
August 2014 €237.59
August 2015 -€267.82
December 2014 €375.88
December 2015 -€1,161.97
February 2015 -€603.87
February 2016 -€124.71
January 2015 €75.11
January 2016 -€1,044.35
But what I want now is for it to display in chronological order as oppose to Alphabetical order.
For example
January 2014
February 2014
March 2014
etc.
I will consider that your TransactionDate field is defined as String
If you want to order by this text field in Access, you will have to use DateValue() function.
That would give:
SELECT TransactionDate FROM yourTable ORDER BY DateValue(TransactionDate)
If your field is already formatted as a Date field, then simply use order by TransactionDate to make it work.

Powerpivot: year to date vs year to date previous year

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.

MS Access grouping query spanning start and end dates

I would like to get a running tally of how many widgets were/are rented at any one time, by month, by year. Data is held in an MS Access 2003 db;
Table name: rent_table
Fields:
rentid
startdate
enddate
rentfee
rentcost
bookingfee
Something like; Count number of rentid's that fall between month/year, then group them?
e.g. if a widget was rented from 5th Jan 2014 to 8th April 2014 it would appear as a count in Jan, Feb, Mar and April tally's.
Many thanks.
EDIT
More details (sorry);
Access db is fronted by classic ASP.
If possible I don't want to create any new tables.
No input is required in order to run the report.
There are around 350-400 widgets that could be rented at any one time.
Each widget is rented exclusively.
Report output example;
Month | Year | NumRented
Jan 2014 86
Feb 2014 113
...
Can a query pick up dates within dates? So literally do a count of the table where date >Dec 31st 2013 AND <1st Feb 2014 (to grab a count for all of January 2014) and would that include the example of the rent starting on the 5th Jan? So I could just do twelve counts for each year?
create a calendar table, e.g.
table = cal_yyyymm with one column dt_yyyymm as numeric field
populate the table with ... say 5 or 10 years of data
201401 201402 201403 ... 60 or 120 rows, a small table
make a sql
Select
dt_yyyymm,
count(*) as cnt
From cal_yyyymm
Left Join rent_table
On format(startdate,"yyyymm") >= dt_yyyymm
And dt_yyyymm >= format(enddate,"yyyymm")
think about the complications in the data -- --
widget was rented from 5th Jan 2014 to 8th Jan 2014
and again rented from 11th Jan 2014 to 21st Jan 2014
does this count at 1 or 2 in the month?
if it is 1, then the sql gets more complicated because
the rent_table first needs to have its dates converted
to yyyymm format, and second needs to be de-duped on rentid,
and third then joined to cal_ On the dates...

Previous Year's End Value

I'm trying to retrieve the previous year's end value of a measure.
I know this code gets the value of the previous year, but at the same point in time during that year (so Mar 2012 looks to Mar 2011).
([Measures].[MeasureName], ParallelPeriod([Time].[Calendar].[Year]))
I'd like any date in 2012 to look at the last value in 2011 (Dec 2011). So if we're looking at the Year level of 2012 or any Month level, it all points to Dec 2011.
where are you trying to do this? On a MDX query? Or on a KPI?
Like you can access the value of Dec 2011 like this for example:
ParallelPeriod([Time].[Calendar].[Year], 1, [Time].[Calendar].[Year].[December 2012])
Combine the time functions:
ClosingPeriod([Time].[Calendar].[Month], Ancestor(ParallelPeriod([Time].[Calendar].[Year], 1), [Time].[Calendar].[Year]) )