I have an Access table that includes a column called ClaimDate. I have a report that shows various things, and the user form for the report asks them to enter the date range for the dataset they wish to display on the report. However, at the bottom of the report I have a running tally for the year. It all works just fine, but I am hardcoding the dates at the bottom like such;
WHERE tbl_CSRQA.CustomerServiceRep=[forms]![frm_CSRErrorTracking]![CSRNameCB] AND tbl_CSRQA.ClaimDate Between #7/1/2019# And #7/31/2019#
What I would like to do is keep the hardcoding for the month/day, but change the year to just the current year. That way I don't have to go back and update all these queries when 2020 hits.
I know I can use the Year(Date()) function to get the current year, but I am having troubles integrating that into my query. I assumed it would be something like this;
WHERE tbl_CSRQA.CustomerServiceRep=[forms]![frm_CSRErrorTracking]![CSRNameCB] AND tbl_CSRQA.ClaimDate Between #7/1# & Year(Date()) And #7/31# & Year(Date())
However that just gives me an error.
Here is the full query;
SELECT tbl_CSRQA.ClaimantAdded, tbl_CSRQA.DocsPhoneCall, tbl_CSRQA.InsdDriverVehInfo, tbl_CSRQA.LossInfo, tbl_CSRQA.TemplateCalNotes, tbl_CSRQA.EmailtoLiab, tbl_CSRQA.ReserveScreen, tbl_CSRQA.InsNamePhone, tbl_CSRQA.Clerical, tbl_CSRQA.AdditionalSteps AS [Total Claim Errors Jul]
FROM tbl_CSRQA IN '\\blcorp\shares\Claims\Liability Claims\Correspondence\CAST Database\Protective Insurance CAST Database Tables.accdb'
WHERE tbl_CSRQA.CustomerServiceRep=[forms]![frm_CSRErrorTracking]![CSRNameCB] AND tbl_CSRQA.ClaimDate Between #7/1/2019# And #7/31/2019# AND
(tbl_CSRQA.ClaimantAdded="No" OR
tbl_CSRQA.DocsPhoneCall="No" OR
tbl_CSRQA.InsdDriverVehInfo="No" OR
tbl_CSRQA.LossInfo="No" OR
tbl_CSRQA.TemplateCalNotes="No" OR
tbl_CSRQA.EmailtoLiab="No" OR
tbl_CSRQA.ReserveScreen="No" OR
tbl_CSRQA.InsNamePhone="No" OR
tbl_CSRQA.Clerical="No" OR
tbl_CSRQA.AdditionalSteps="No");
All I really need to do is just update the query so that the hardcoded dates just look for the current year, instead of me having to input "2019" or "2020".
Related
I have a union query that pulls objects and their dates from a query and table with similar fields so that I can display them together on a report. The union query (qry_ObjectUnion) has a WHERE function that prompts the user to enter a start and end date.
SELECT [Object], [DateObject]
FROM qry_ObjectQuery
WHERE (((Year([DateObject])) Between [Which year would you like this report to start?] And [Which year would you like this report to end?]))
UNION SELECT [Object], [DateObject]
FROM tbl_ObjectTable
WHERE (((Year([DateObject])) Between [Which year would you like this report to start?] And [Which year would you like this report to end?]));
On the report, I’d like to dynamically display the start and end year the user chose for the report. To accomplish this, I wrote a second query (qry_ObjectUnionYears) off of the union query.
SELECT Min(Year([DateObject])) AS MinYear, Max(Year([DateObject])) AS MaxYear
FROM qry_ObjectUnion;
The second query returns the start and end year as expected when accessing (double-clicking) the query directly, but opening the report yields different results. In the report, I have a textbox with a MinYear control source of:
=[qry_ObjectUnionYears]![MinYear]
When accessing the report, the first two message boxes ask for the start and end year, but the third message box asks for a parameter value for qry_ObjectUnionYears and proceeds to return a #Error no matter what I enter.
Can anyone help me out? Thanks in advance!
I figured it out after browsing online some more. The textbox can self-reference the parameters entered into the report as so:
=Report![ObjectReport]![Which year would you like this report to start?]
There is no need to write a second query as I originally tried to do.
I'm currently struggling with how to produce a Fiscal Year parameter, so its values start with Current year, but also contain records from all previous years, and then have all following values be each following year.
So the Fiscal Year would look roughly like the following
Current (I would want to include all previous Fiscal years in this as well),
F18,
F19,
F20,
etc. etc.
As of right now, I have all fiscal years on the drop down, starting with the earliest fiscal year that exists in the database using the following query to populate the parameter dropdown.
SELECT DISTINCT FiscalConsideration FROM dbo.Currency
Which would look like this
F12,
F14,
F15,
F16,
F17,
F18,
etc. etc.
Then I filter the results based on the selected Fiscal year.
Question 1
Is there a way where I might be able to do this, have all records from current fiscal year and prior on one value and all individual fiscal years after?
Question 2
I have also discovered that I can't have this be multi-select AND accept NULL's as well. Might I be able to convert nulls to a custom string or something and have that be an option as well?
I ended up doing it by incorporating more of the logic I wanted into the computed column in SQL Server Management Studio with another case when for past records, and changing nulls with isnull to 'TBD'
I've created a new measure which uses [TotalSales] and 'SAMEPERIODLASTYEAR' to calculate the previous year's sales, see below:
=CALCULATE([TotalSales], SAMEPERIODLASTYEAR(Dates[Date]))
This all works fine if I create a pivot that displays individual dates (e.g. 01/01/2015) and then the new measure 'previous year sales' value next to it. My problem occurs when I want to change the pivot and display previous year sales by year, quarter or month - with any of these options I get no sales value.
I'm using a 'Dates' table which is linked to the Sales table.
Am I right in thinking I can re-aggregate sales in this way? I have seen an error message which says something about not been able to aggregate a non-contiguous value or date.
I've had a good look to see if anyone else has experienced the same problem, but can't see anything. Any guidance would be helpful.
Regards,
Martyn
Yes you can re-aggregate in this way. Your formula is correct would handles the changes to the aggregation level.
I would check that your 'Dates' table is marked as a date table. Ensure that the year, quarter & months are in this date table and not in your Sales table. Make sure that your date table has one record for each day between the beginning of your sales data set and the end. Check behavior in Power View if you are using Excel 2013.
I have a report which runs weekly and in one of the tables it says week1, week2 etc all the way to the recent week (e.g. week28 currently)
This table is in the report and I would like the week28 value to be in the title. The title reads "summary report for" I want to place the week number at the end so every week the report is run it changes.
There are also a couple of other places I would like to place the dynamic value but i'm guessing the code will be the same.
Assuming you have a sorted dataset called "MyDataset" with a column that contains the week names called "Week", you could simply use the following expression:
=Last(Fields!Week.Value, "MyDataset")
This returns the last value in the Week column of MyDataset.
Alternatively, you could construct the week number using some of the date functions, for example the datepart function
I'm building a report in Reporting Services 2005 based on a SSAS 2005 cube. The basic idea of the report is that they want to see sales for this fiscal year to date vs. last year sales year to date. It sounds simple, but being that this is my first "real" report based on SSAS, I'm having a hell of a time.
First, how would one calculate the current fiscal year, quarter, or month. I have a Fiscal Date Hierarchy with all that information in it, but I can't figure out how to say: "Based on today's date, find the current fiscal year, quarter, and month."
My second, but slightly smaller problem, is getting last years sales vs. this years sales. I have seen MANY examples on how to do this, but they all assume that you select the date manually. Since this is a report and will run pretty much on it's own, I need a way to insert the "current" fiscal year, quarter, and month into the PERIODSTODATE or PARALLELPERIOD functions to get what I want.
So, I'm begging for your help on this one.
You'll probably need to modify the SSRS MDX by hand to do this. It is possible to get SSAS to use "Today", it is usually done as something like this:
WITH
MEMBER [Today]
AS {
StrToMember("[Date].[Date Key].&[" + Format(now(), "yyyyMMdd") + "]")
}
SELECT
[Measures].[Some Measure]
ON COLUMNS
FROM
[Cube]
WHERE
{[Today]}
You'll need to change that to fit your own cube structure of course.
So, given that you have fiscal year, and you want to plug values in, modify the above to fit? Put together a string like I showed you that equates to the values you want to use. It sounds like you're OK after that?
You should be able to figure this out using various functions which can tell you 'where you are in the hierarchy'
e.g.
http://www.sqldev.org/sql-server-analysis-services/find-parent-of-current-day-10080.shtml
I know it is a "bit" too late but for people reaching this question page this might help:
IIF(Month(Now()) > MonthOffSetNumber, Year(Now()) + 1,Year(Now()))
This is for getting the current fiscal year. This will be applied in something like this:
SET CurrentFiscalYear AS
(
StrToSet("[Dim Date Name].[Fiscal Year].&[" + Format(IIF(Month(Now()) > MonthOffSetNumber, Year(Now()) + 1,Year(Now()))) + "]")
)
This will help for later cross join in the query.
WE find an easy way to calaculate fiscal period to date date in mdx by using parameters. Imagine that we have BeginDate (01/04/2014) and EndDate (31/03/2015). Here are the formulars. Click on Parameter "beginDate" in Report Data - right click parameters - Specify values - add expression value:
=DATEADD
("M"
,IIF(Month(Today())<4
,-Month(Today())-8
,-Month(Today())+4
)
,DATEADD("D",0-DATEPART("D",Today())+1,Today()))
Do the same for the second parameter "EndDate" and set the Defualt values - Specify values and add expression value:
=DATEADD("D",-1,DATEADD("M",12,DATEADD
("M"
,IIF(Month(Today())<4
,-Month(Today())-8
,-Month(Today())+4
)
,DATEADD("D",0-DATEPART("D",Today())+1,Today()))))
Now your ssrs report will have the fiscal period as default period.
Moise Kabongo