SSRS select parameter month and change par. first and last day of this month - reporting-services

i need to create parameter list of months and then (after select) recalculate two others paramateres in date format ([first day] and [last day]) of this month, can you please help me?

You are querying a database server to generate the list of months, although there's no need to do that. I suggest to rather create a list of months in the report and let the report calculate the month's names, so the language depends on the Language setting of the report (which can be the language configured in the user's browser).
For example, to calculate the Label for the Value 1, use an expression like =MonthName(1).
The Parameters FirstDay and LastDay (or just the values whenever you need them) can be calculated using these expressions:
FirstDay: =DateSerial(Today.Year, Parameters!Month.Value, 1)
LastDay: =DateSerial(Today.Year, Parameters!Month.Value, 1).AddMonths(1).AddDays(-1)

Related

How to define Row Data group in SSRS if we have two parameters to be considered?

Im new to SSRS reporting. Im trying to edit in *.rdl file, where it has row data grouping to view data for a month.
eg: =Fields!EndOfMonth.Value
Here EndofMonth will return September 30th /October 31st etc. So table is grouped by one month data.
I need to edit this for a custom data range.
eg: startdate='2019-09-05', enddate='2019-10-12'
So, report table should display rows between September 5th to October 12th.
I have both startdate enddate parameters defined in the *.rdl file.
But I dont know, how i can switch between both date ranges based on condition. that is , if companyid<>50 pick custom range else standard.
eg:
I defined like this, but here i could point only one parameter(i used enddate only).So report shows rows between October 1st to 12th only.
How can I modify the condition?
=IIF(Parameters!CompanyId.Value<>50,Fields!EndofMonth.Value, Parameters!EndDate.Value)
EDIT
I have 2 datasets defined to switch between companyids.
I modified above condition based on Nicks answer, but i get lookup function can not be used with functions issue.
I tried following both way, but getting same rows again and again
=IIF(Parameters!CompanyId.Value<>50,Fields!EndofMonth.Value,
IIF(Lookup(Fields!TankDateCombo.Value, Fields!TankDateCombo.Value,Fields!Date.Value,"Dataset2")
>= Parameters!StartDate.Value,Fields!EndofMonth.Value,
Parameters!EndDate.Value))
=IIF(Parameters!CompanyId.Value<>67,Fields!EOM.Value,
IIF(Day(Lookup(Fields!TankDateCombo.Value, Fields!TankDateCombo.Value,Fields!Date.Value,"OESNeoData"))
>= Day(Parameters!StartDate.Value), Fields!EOM.Value,
Parameters!EndDate.Value))
MY dataset contains following data;
I fixed this by simply deleting that row group and passing start/end dates for both datasets

Filter data set by month

I'm using an embedded data source of type SharePoint List.
I use a parameter that a user can modify that will filter the data set by the month. I've seen a few examples but they all either use a SQL query or only filters on the exact day rather than the month.
I added a parameter ParamMonth and gave it the data type of Date/Time. I can see this adds a drop down box to my report which is exactly what I want. Ideally, I would like to add the name of all 12 months or something similar, but I don't know how that will work out when the data exceeds a single year. Now, that I've got my Report Parameter added, I need to add it to my dataset to filter on. This is where I'm stuck.
An easy way could be creating a parameter type Integer and set all months in Available Values tab as follows (I just set five months for example).
Then go to the DataSet Properties / Filter tab and use the below settings.
For expression use:
=MONTH(Fields!Date.Value)
Where Date is the field that you will use to filter by month. In Value you have to use:
=Parameters!Month.Value
UPDATE: Provide year selection.
The best approach for this is getting the available values from a DataSet, in this case your SP list.
Just create a calculated field in your dataset with available years (it can be a copy of the SP list dataset), call it calculatedYear and use:
=YEAR(Fields!Date.Value)
Now create a Year parameter of Intenger data type, and set this settings:
Where DataSet15 is the DataSet name that feeds your parameter with the available years.
Then just add another filter in your dataset:
Note you will need two datasets one to get the available years and
other the dataset you need to filter.
Let me know if this helps.

Dynamically change column names as week number on every weekly run

I want to build a SSRS report that has column as week numbers - 8 weeks for 8 columns starting with current. This report is run every week and current week number is set then. So both column names and their values should change .Is it possible to build something like this in SSRS?
I tried doing this with a dynamic SQL based stored proc in dataset. However for every run I don't even see the columns values updating dynamically
Here's an example :
Also I am trying to avoid these week numbers as row values and then using matrices
My stored proc looks something like this
declare #n tinyint = datepart(wk, getdate())
declare #n1 tinyint = (#n+1), #n2 tinyint =(#n+2), #n3 tinyint =(#n+3), #n4 tinyint =(#n+4), #n5 tinyint =(#n+5), #n6 tinyint =(#n+6)
exec ('Select b.sku, b.['+#n+'], b.['+#n1+'], b.['+#n2+'], b.['+#n3+'], b.['+#n4+'], b.['+#n5+']...
Will appreciate any help in this direction.. many thanks!
When working with SSRS it's generally best to avoid dynamic SQL and pivoting the data in the SQL. Use the SQL to get the raw data you need and then let SSRS do the pivoting and aggregation. This way you take advantage of what they each do best. I know you said you want to avoid matrices, but it is the best way to make the report dynamic.
So you should either return all the data in one dataset and use filters on your matrices OR write two queries and have each one populate a matrix. BTW a matrix is just a table with a column group added, so don't be intimidated by them.
There are 2 ways to do this with a standard tablix.
Calculate the column headers as expressions using concatenation of Wk and some date math to find the correct week number and return the same sort of thing from your query (e.g. columns are current_week, week_minus_1, week_minus_2...)
Return the column headers as additional columns in your query that are the same value for every row (e.g. ColHeader0, ColHeader1...). Your data columns would still be relative weeks (e.g. ValueWeek0, ValueWeek1...). In your report the column header would have an expression like =First(Fields!ColHeader0.Value). This is a more flexible approach since it lets you pick 8 historical weeks instead of only the last 8 weeks if you add a parameter.
EDIT - Clarifications
The reason that you get the blank column Wk48 is approximately that you have created your report looking for that column that won't be there the next time. SSRS looks for exact columns. You should you use relative column names for either of the options I have specified:
exec ('Select b.sku, b.['+#n+'] as Wk0, b.['+#n1+'] as Wk1, b.['+#n2+'] as Wk2, b.['+#n3+'] as Wk3, b.['+#n4+'] as Wk4, b.['+#n5+'] as Wk5...
This will allow you to populate the aliased Wk0 column with the appropriate current week data and still make sure that it can be consistently referenced as the base week by SSRS.
To change the column headers you can:
Independently calculate the week numbers in SSRS in the column header expressions: ="Wk" + CStr(<correct week calculation>).
Return the column headers in the result set and access them in the column header expression:
exec ('Select b.sku, b.['+#n+'] as Wk0, b.['+#n1+'] as Wk1, b.['+#n2+'] as Wk2, b.['+#n3+'] as Wk3, b.['+#n4+'] as Wk4, b.['+#n5+'] as Wk5..., ''Wk'''+#n+' as ColHeader0, ''Wk'''+#n1+' as ColHeader1...
and reference the returned column headers from the SSRS column header expression as =First(Fields!ColHeader0.Value).
Here's a solution that worked for me:
Create parameters (say CurrWk, CurrWk1) ,set as hidden and store 'Default value' and 'Available value' equals to current week number (datepart(wk, now()) and any subsequent week by doing a +1, +2, +3.. etc.
Write a query expression . Click onto fx beside dataset query space and write the select query for your program embedding parameter values in the expression window. For eg ="Select SKU, [" & Parameter!CurrWk.Value & "] as Wk1,
[" & Parameter!CurrWk.Value & "] as Wk1 from Sales_Table"
Before passing this query as a 'command text expression' please ensure this query is working in sql ssms.
Save the expression. Now find 'Fields' tab on the left hand side panel.You need to map the fields manually from the query here. If this is not done, there is a very high chance you seean empty field list and wont be able to access them at all. This may be because ssrs do not store query metadata directly from expressions.
You can avoid part of the issue by having atleast the static fields , for example here SKU listed in the 'Fields' list by first running a sql query with static field(select SKU from Sales_Table ). You can then go back to update dataset- change query to expression and embed the parameterized field names.
Map field names. In this example I chose 'Query Type' fields and set Field names as SKU, CurrentWeek, NextWeek and mapped to source SKU, Wk and Wk1 respectively.
Click on 'Refresh Fields' at the bottom. Now you have a dataset with the complete field list. Use these in charts, tables . Run it every week and note the numbers changing as expected.
In case you are using this dataset in a table, make sure you set headers with Labels of Parameters (for eg here I did =Parameters!CurrWk.Label for col with current week data)
That's it!

SSRS Dynamic Date Parameters

I'm fairly new to reporting and need help with the following?
I have a report that has two date parameters statically set to default to the last financial year. i.e. the FROM parameter 01/04/2015 and the TO parameter 31/03/2016.
When the actual date next year is 01/04/2017 I need these parameters to change forward by one year, I know I maybe able to do it with a case statement and a getdate + dateadd .
I have a small table which creates a year period based on certain dates which I then join onto the data then I use that to filter.
for instance:
1516
1617
1718
so if #year_period = 1516 then the previous year would simply be #year_period-101 and the future would be #year_period+101

sql query to get a scheduled report to run for that curent month only

I have an SSRS 2005 report that has a dataset for to an Oracle database. The report that i have essentially just pulls all data back from an audit log. This report works perfectly fine and i have scheduled thi to run and send an email using the new subscription method within SSRS.
The only issue i have is i want the report to run on the last day of the month (its set up to do this alreday) and run the report based on that month only. Getting the report to run specifically for a month is what im unsure on? I though i would be able to set parameters within the report but these only enable my user to select a calendar date?
Is there a DATEADD or DATEPART type of function i can use to complete this task?
Regards
B
Best bet would be to set up a dynamic date default for the date patameter at the report level, and set up the subscription to use this default value, so whenever the subscription runs it would automatically have the appropriate date.
Probably the easiest thing to do is set the parameter as the current date, if that would work, e.g. something like =Today(). So that will be calculated whenever the subscription runs.
You can set the default value for whatever you need; first day of the current month, etc. You should able to set whatever value you need without too much trouble.
So for the first day of the month something like:
=DateSerial(Year(Today()), Month(Today()), 1).
Users running the report ad-hoc could just reset the parameter as required.
I'm assuming the report handles the amount of data to return correctly assuming the right data parameter is sent.
2 Parameters #DateFrom and #DateTo
Default Value for #DateFrom that outputs the first day of the current month:
=DateAdd("d",-Day(Today())+1,Today())
Default Value for #DateTo that outputs the last day of the current month:
=DateAdd("d",-Day(Today())+1,DateAdd("m",1,Today()))