SSRS 2008 - How to link 2 or more year parameters into 1 - reporting-services

After some research, I see that blending parameters is a popular topic but I haven't found a solution to this specific situation. Shortly said, I have 3 parameters from various datasets all stating the same year and I want to blend them (visually) into 1 so to eliminate this redundancy for my report's end-user.
In the "Available values" from "Parameter properties", all the values are taken from a dataset (hidden) and the "value field" is [Measures].[ParameterValue] from their corresponding hidden dataset.
When I "show hidden datasets" and go into "text mode" of each of these hiden datasets are these are the 3 MEMBER [Measures].[ParameterValue] AS :
[Time].[Financial Year].CURRENTMEMBER.UNIQUENAME
[Financial Period].[FP - Year].CURRENTMEMBER.UNIQUENAME
[Time exit].[Financial Year Exit].CURRENTMEMBER.UNIQUENAME
When you look at what value this gives, they have the following output (accordingly):
[Time].[Financial Year].&[2017]
[Financial Period].[FP - Year].[FP - Year].&[2017]
[Time exit].[Financial Year Exit].Financial Year Exit].&[2017]
A. So, in my opinion, since the "roots" of each [Year] parameter value are different I need to create a dataset or a member within each of these hidden datasets that replaces this [2017]. Is that "doable" and, if yes, any guidance on how?
B. If not, another outcome would be acceptable as well: the end user would need to generate mostly current year and current year-1. To tackle this I made a Template "Year" DS with the same content as in FP - Year and added the following members:
Member [Measures].[Last Year] as 'YEAR(NOW())-1'
Member [Measures].[Current Year] as 'YEAR(NOW())'
I inserted them into SELECT and previewed, it displays 2 new columns with 2017 and 2016. Then I went and changed in that PF-Year parameter's DS, value and label and I get an error. Any suggestions?
Any suggestions on this?
EDIT1: I have tackled B. and found a solution to it, I simply created the following 2 Default values for each parameter:
Current year: ="[Time].[Financial Year].&[" + CStr(Year(Now())) + "]"
Last year: ="[Time].[Financial Year].&[" + CStr(Year(Now())-1) + "]"
However, even though with this result I presume it will minimize the number of actions for the end-user, I would still prefer having 1 parameter showing instead of 3...
EDIT2 & partial solution I found another solution for A., it's not exactly what I wanted but it kind of gets the job done.
Created a new Year parameter with 2 available values: [CurrentYear] and [LastYear]
For each of the default values of each other parameter, I swaped the 2017 and 2016 values for CStr(Parameters!Year.Value(0)) and for CStr(Parameters!Year.Value(1)) accordingly. Example: ="[Year exit].[Financial Year exit].&[" + CStr(Parameters!Year.Value(0)) + "]".
In the options of each parameter, I set them as "Hidden" expect for my new Year parameter.
Now, I have 1 Year parameter with a dropdown list displaying Current Year and Last Year.
Even though this alleviates the issue, is there anyway to have a similar outcome but with the drop down menu displaying the actual years? i.e. it would be dynamic so in years to come, there would be 2018, 2019, etc. that would pop up? This way the end user would be able to compare not only current and past year but any 2 years?
Thanks to all!
EDIT3 Here is a screen shot of where I am at, at this point:
EDIT4
I have arrived to a fix: since I know that the end-users will only be comparing 2 years at a time (so 2 default values per parameter), I left hidden 2 parameters out of 3 and for the 2 hidden, I changed their default values.
So, I kept #[Financial Year] as my main parameter and the others have the following default values:
#[FP - Year]:
="[Financial Period].[FP - Year].[FP - Year].&[" + CStr(Parameters!Financial Year(0)) + "]"
="[Financial Period].[FP - Year].[FP - Year].&[" + CStr(Parameters!Financial Year(1)) + "]"
#[Financial Year exit]:
="[Year exit].[Financial Year exit].&[" + CStr(Parameters!Financial Year(0)) + "]"
="[Year exit].[Financial Year exit].&[" + CStr(Parameters!Financial Year(1)) + "]"
And voilĂ  the result:

I'd suggest two ways:
1: SSRS: add an invisible parameter (i.e. CurrentYear) and run in your MDX query the following:
StrToMember('[Time].[Financial Year].&[' +#CurrentYear + ']')
2: MDX: add a dynamic calculated members for each hierarchy:
member [Time].[Financial Year].[Current Year] as
StrToMember('[Time].[Financial Year].&[' + Format(Now(),'yyyy') + ']')
See my blog post for more details.

Related

SSRS Matrix columns show currrent month

I'm stuck with a problem in SSRS 2012 that maybe is very simple:
I have a matrix with a group row (employee) and a group column (last 12 months); the values are COUNT(practicesDone) - i.e. the amount of practices worked.
I want the matrix to show an extra column on the right (after all the columns of the months, and clearly outside the column group) with again the number of practices for the current month.
Is it possible to achieve that?
thank you in advance!
You can do this, it's pretty simple.
I have assumed that your dataset contains a column that has a date for each entry and that the data returned only covers 12 months so the same month would not appear for different years. If your data does have multiple years, look at the second expression below.
Right-click your month column and then to "Insert Column --> Outside Group - Right"
Now set the expression for the text box to
=COUNT(IIF(MONTH(Fields!myDateColumn.Value) = MONTH(TODAY()), 1, Nothing))
You could swap COUNT for SUM and it should do the same thing but either will work.
All we are doing here is comparing the all data in scope which, due to the placement of the text box means the scope is the entire rowgroup. Then for all that data, check if the month matches the current month, if it does set it to 1 is not set it to nothing then count/sum all results. Count conveniently ignores 'nothing'.
If you data covers more than 12 months then you can still do this but you'll have to add a bit more to handle years and months like this.
=COUNT(
IIF(
MONTH(Fields!myDateColumn.Value) = MONTH(TODAY())
AND YEAR(Fields!myDateColumn.Value) = YEAR(TODAY()),
1,
Nothing
)
)

How to use expression builder to create a file name with date even for the first day of the month

I have an SSIS package that runs each morning to pull the previous days file from an FTP server. I am using the code below to create the file name using the previous date. Everything works great with this except when today's date is the first day of the month. for example, if ran today (3/1/2021) this returns name_of_file_20210328.xml.gz, however yesterday's date is 2/28/2021 not 3. How do i update this to say if today's date is beginning of month return mm - 1?
"name_of_file_" + (DT_STR,4,1252)(DATEPART("yyyy",GETDATE())) + (LEN((DT_STR,2,1252)(DATEPART("MM",GETDATE()))) == 2 ? (DT_STR,2,1252)(DATEPART("MM",GETDATE())) : "0" + (DT_STR,2,1252)(DATEPART("MM",GETDATE()))) + (LEN((DT_STR,2,1252)(DATEPART("dd",DATEADD( "day",-1, GETDATE())))) == 2 ? (DT_STR,2,1252)(DATEPART("dd",DATEADD( "day",-1, GETDATE()))) : "0" + (DT_STR,2,1252)(DATEPART("dd",DATEADD( "day",-1, GETDATE())))) +
".xml.gz"
Create a variable, Yesterday of type DateTime. Specify that it uses an expression and use the following expression. This provides a consistent reference point you can test against and if you disable the expression, allows you to specify a date for boundary/special case checking (like a leap year 2020-03-01)
DATEADD("DAY", -1, #[System::StartTime])
The next steps, especially if you're starting out, is to build the date parts in separate variables. It doesn't cost any extra to use lots of variables in your package and makes troubleshooting so much easier.
Add a new variable, YearString of type String.
(DT_WSTR, 4)datepart("YYYY", #[User::Yesterday])
That was easy.
Now we need to deal with create a zero, left padded string. Right now, your expression looks like it's trying to determine if day or month has 2 digits. I have a cleaner expression.
We're going to convert the day/month to a string and then prepend a zero to it. For Jan-Sep, we'll end up with a 2 character expression, Oct-Dec, we'll have a three character expression e.g. 011. For Day, similar bit where it's 01-09 or 010-031. We will then take the last two characters from the string. For the two character strings, it's a no-operation and for the three character variant, it gets us what we want.
Add Variable MonthString, as type string, to your package
RIGHT("0" + (DT_WSTR, 2)datepart("MONTH", #[User::Yesterday]), 2)
Add Variable DayString, as type string, to your package
RIGHT("0" + (DT_WSTR, 2)datepart("DAY", #[User::Yesterday]), 2)
Take a moment and look at your Variable collection. You can see that you have all the building blocks needed to properly construct your YYYYMMDD string. If something is wrong, it's small enough snippet to play with it. If not, break it up into smaller Variables.
Now that we have defined #Yesterday and then built YearString, MonthString and DayString off of Yesterday, all we have to do is bring it all together with the concatenation + operator
Back to the Variable well, creating #CurrentFileName of type string
"name_of_file_" + #[User::YearString] + #[User::MonthString] + #[User::DayString] + ".xml.gz"
Results in a value of name_of_file_20210216.xml.gz
Not addressed in this answer but things you should think about
What happens when the job doesn't run at all today (server fails horrifically, the data source is down, etc)? To pick up and process 2 days ago file, you would need to edit this package, run it through whatever change review process is applicable, deploy to prod, run it and then go back to the process yesterday file package.
That's not fun to type much less consider. You certainly aren't going to change the server time to trick the expression into being yesterday.
I am an advocate for passing the run date to the package (mechanism depends on how you deploy/run packages). In that situation, it's been my experience that it's a far easier bureaucracy fight to change the calling parameter (because no "code" has changed) than to get an emergency code change run through.

Implementing a date range in SSRS with the data coming from a cube

I have been trying to implement a date range parameter in SSRS 2015. The data is from a cube. I dragged my date into the dimension box of the query designer and went into the parameter tab to change the fromDate and toDate to date/time format and this resulted in the following MDX query.
SELECT ( STRTOMEMBER(#FromDate, CONSTRAINED) :
STRTOMEMBER(#ToDate, CONSTRAINED) )
My date format is dd/mm/yyyy. I have looked on several forums and tried a few method but continued to get the error:
The restrictions imposed by the CONSTRAINED flag in the STRTOMEMBER function
were violated
Thank you in advance
Your parameters will need to be formed in full address mdx. e.g. #FromDate could be this - I've used the DateKey:
'[Date Dim].[Date Hier].&[20180301]'
So some concatenation, within ssrs, would be required before getting passed:
"[Date Dim].[Date Hier].&[" + 20180301 + "]" //<<you'll need to change to the names used in your cube
I'd also be tempted to use strToSet as you want a set. So mine might be something like:
( STRTOSET( "[Date Dim].[Date Hier].&[" + #FromDate + "]:" +
"[Date Dim].[Date Hier].&[" + #ToDate + "]" , CONSTRAINED) )
Here is a good reference: Range parameter on the MDX-query
The error message you received means that the parameter values do not exist in the cube in that format. To solve this you need to create a field that can be formatted and displayed to users without changing the value that the query uses.
When you create parameters in the Query Designer, it automatically creates hidden datasets which populate the Available Values for the parameter. To see this, right-click on the Datasets folder and select Show Hidden Datasets.
Now, go to the dataset properties and add a calculated field in the Fields tab. This will be your nicely formatted date.
In the parameter properties for each parameter, go to the Available Values tab. Leave the Value field the way it is, but change the Label field to the new column you created.
Now the dropdown will show the friendly label, but use the real value behind the scenes!

How to iterate over table in Access 2010

I would like to iterate over the rows in my Payment table. User chose for what month and year has wants to book and I want to check in the each raw if this house was booked for this year and month. I want to compare if
HouseID == chosenHouseID && BookingMonth == chosenBookingMonth &&
BookingYear==chosenBookingYear.
If this is true it should pop out message box with info that house was already booked for this month. Also if user chose more than one month i.e. numMonths would be 3, it should increment value of the month (which is a text) it should go to the next value (if there is no next value then it should do mod 12) and do the checking again. Maybe it will be necessary to switch data type of BookingMonth to numeric?
However I hope I was clear what I want to do. I have experience with Java, C, Python and Visual Basic, but I did not do much in Access so it is quite confusing. I could not find the any useful info how to perform this operation. Please advise me on my issue.
Thank you
Yes, you definitely should store the [BookingMonth] as numeric. Maintaining a "month" column as text will be a nuisance in the long run, since "August"<"January" and "12"<"2". You'd have to do at least a certain amount of juggling to convert the text values to numeric values, so make like easy for yourself and just maintain them as numeric. (Note that you can always format them as text if you want to use them in reports.)
As for your search requirements, if the user supplies a [chosenBookingYear], [chosenBookingMonth], and [numberOfMonthsToBook] then you can use the VBA DateAdd function to derive [endOfBookingYear] and [endOfBookingMonth] safely, accounting for "next year" values...
endOfBookingYear = Year(DateAdd("m", numberOfMonthsToBook - 1, DateSerial(chosenBookingYear, chosenBookingMonth, 1)))
...and...
endOfBookingMonth = Month(DateAdd("m", numberOfMonthsToBook - 1, DateSerial(chosenBookingYear, chosenBookingMonth, 1)))
Finally, to perform the lookup without looping through individual rows you can concatenate [BookingYear] and [BookingMonth] together to create something like "2013/05" using...
BookingYear & "/" & Format(BookingMonth, "00")
...so then you can create a SELECT query something like this:
SELECT * FROM Payment
WHERE HouseID = chosenHouseID AND
(
(BookingYear & "/" & Format(BookingMonth, "00"))
BETWEEN (chosenBookingYear & "/" & Format(chosenBookingMonth, "00"))
AND (endOfBookingYear & "/" & Format(endOfBookingMonth, "00"))
)

Totals on a report summary

I have an Access Report. In the footer section of my report I have a list of different totals. I am looking to create these totals based on a time criteron. For example:
Im looking for a count of the included records. I need to determine a count based on either current- 3 months, 4-6 months, 7-12 Months and 13+ Months.
I have created a DateDiff() expression to determine the amount of months. I have created another expression to assign a letter based on what group the result would belong to. For example:
A = Current - 3months
B = 4-6 Months
C = 7-12 Months
D = 13+ Months
How could I use the assigned letter as a count on my report? Could I make a statement in my control source for my display text box to accomplish this?
I'm not sure where to go next...
In the reports On_Open event write some VBA to store the values from your DateDiff into several different String Variables, and then if your footer is a simple text box just update the values e.g.
txtFooter = "3Mnths - " & str3Mnths & " - 4/6Mnths - " & str46Mnths