SSRS expression - show value from field depending another field - reporting-services

I have two columns in my function which are Actual_Forecast and Month. On my reports I have a column for each month Jan, Feb, Mar etc.....
I would like to add an expression in the January (and the other columns) header to show if the month is actual or forecast, Jan = Actual, Dec = Forecast.
So if the field = Jan then show what is in the Actual_Forecast
I've tried a number of things but expressions and SSRS is still very new to me.
I thought it would be something like =Fields!date_month_name.Value = "October", = Fields!actual_forecast.Value

You could set your Expression in each of the column header text boxes. Say for January
= IIF(MonthName(Month(Today()) = "January", "Jan - Actual", "Jan -Forecast")
Response To your Comment
You might try in each of the header text boxes. Again an example for January but each header would have the appropriate moth name.
= IIF(Month(Today()) <= Month(Fields!Date.Value), "Jan - Actual", "Jan -Forecast")

You can convert your month value as a first date of the month.
After that use Month function to get integer month value
Can compare your month input value to current month value
If your month value less than or equal to current month it will display 'Actual' otherwise 'Forecast'
Eg:
if your month value is 'Sep'. from above step,
01-Sep-2019
Month("01-Sep-2019") will return 9.
Month("01-Sep-2019")<=Month(Now)
IIf(Month("01-Sep-2019"<=Month("12-Sep-2019"),"Actual","Forecast")
=IIf(Month("01-"+Fields!MonthValue.Value+"-"+CStr(year(now)))<=Month(now),"Actual","Forecast")
Use above code with your month value field in header.

Related

SSRS Expression to return previous month year value

I'm trying to come up with an SSRS expression to return a previous value from the year prior. As you can see in the screenshot, I'm trying to return the value of 22 in the "Prior Year Actual" column. This value aligns with April 2020. The last month I have in the dataset currently is April 2021. Essentially I want to return the value from the year prior based on the last column of April 2021.
Can anyone help with this? Greatly appreciated!
If your month fields are dates in a column group, you could get the MAX date and add it to the dataset.
DECLARE #MAX_DATE DATE = (SELECT MAX(DATE_FIELD) FROM TABLE)
SELECT *, #MAX_DATE AS MAX_DATE
FROM TABLE
Then your expression could use the new field to make it work like you want.
=MAX(IIF(Fields!Date.Value = DATEADD("y", -1, Fields!MAX_DATE.Value), Fields!COLUMN.Value, NOTHING))
This worked! Thank you very much Hannover for your expression suggestion!!
=MAX(IIF(Fields!DateTest.Value= DATEADD("yyyy", -1, MAX(Fields!DateTest.Value)), Fields!Operating_Days.Value, NOTHING))

How to tie the column visibility expression in SSRS to current year and current month?

I have an SSRS report that has all 12 months as columns and one more column called "Year". I already have a condition set that takes the current month of the report run date and displays only the months that have passed. For example, the expression looks like this for March =IIF(Month(today()) < 3, True, False).
Now I have to tie this to the Year column as well. The condition is- if the Year column has years prior to the current year, the condition above should not apply. So, if I am running 2020 data today, all 12 month columns should appear. If I am running 2021 data, I should only see the January column. Can some one please help me with this? And yes, there will only be one year in the "Year" column. The data will never have more than one year.
Thank you.
Edit 1:
If the report is run for 2020, the data should look like this on the report.
If it is run for 2021, only the YEAR and JANUARY columns should appear. Starting February of this year, YEAR, JANUARY, AND FEBRUARY should appear.
As your dataset is not normalised, you will have to set the column visibility on each column as you are doing already.
Try using the following expression. (using March as an exmaple)
=(Month(today()) < 3 AND MAX(Fields!Year.Value, "DataSet1") = YEAR(Today())
Note: The "DataSet1" reference is the name of your dataset. It is case sensitive and must be enclosed in quotes as shown above.
There is no need for the IIF() expression as the above will return true if either condition is met.
Alternative
If your data was normalised (you may be able to edit your dataset query) and looked something like this...
Year Month Amount
2021 1 10
2021 2 15
Then you could simply use a matrix instead of a table, and have a column group by month. There would be no need to set visibility on anything as the data simply is not there so no column would be rendered for the months with no data.

Use of Parameter in SSRS report

I have to fetch data from table MonthWise. I have created a PARAMETER - #SELECTMONTH and kept this parameter as static. I had put specific value in available values i.e.
for eg. Label - Jan Value - Jan
Label - Feb Value - Feb and so on
I have used this parameter in query. i.e.
Select Month FROM Table WHERE Month in (#SelectMonth)
Union all
Select 'Jan-Feb' as Month FROM Table Where Month in ('Jan-19','Feb-19')
Union all
Select 'Jan-Feb-Mar' as Month FROM Table Where Month in ('Jan-19','Feb-19','Mar-19')
Under DataSet Properties > Parameters > Add > Parameter Name - #SelectMonth and Parameter Value - [#SelectMonth] - under this expression is =Parameters!SelectMonth.Value
All this are the factors in report. and when report runs I am able to see SelectMonth Parameter and able to select multiple months and data is been displayed accordingly I select the months.
But this is 50 % of requirement only done. Another requirement is I have to display months at the end of the report, which is written in UNION ALL query. I am able to display it by use of UNION ALL query. But the requirement is to display as per the month selected in parameter checkbox.
For eg. If I select Jan-Feb-Mar, than it should display as
Jan
Feb
Mar
Jan-Feb
Jan-Feb-Mar
But if I deselect for eg. Mar, than it should remove Mar from the Month which is at the end of report. Here I am able to remove from single month, as required month Mar is not showing/data is not been fetched in single month field but it is till fetching month Mar in end where it is joining months Jan-Feb-Mar. I do not even want that month Mar to be joined at end either. it should be removed totally from everywhere. it is should look like as below: but I am not able to do it.
Jan
Feb
Jan-Feb
If anyone can help that how should I put it ? I was wondering to use IF condition, that IF #SelectMonth = 'Jan' then only that much data should be displayed in single month column and even to the join month column.
But i am not able to figure out exactly. so please if anyone can help that will be great.
Thank you so much everyone in advance.

query criteria to show records for a certain month

I have some records in a query with a column of dates. I want it to only show the records that occur in March. This link
https://support.office.com/en-US/Article/Examples-of-query-criteria-3197228c-8684-4552-ac03-aba746fb29d8#bm1 shows the different types of criterion.
The one below in the table describes how to show only what occurs in a particular month:
"Contain a date that falls in a specific month (irrespective of year), such as December
DatePart("m", [SalesDate]) = 12
Returns records where the transactions took place in December of any year."
I don't know what the SalesDate means in the criteria function, and there isn't any explanation on the page.
[SalesDate] implied a Date/Time field named SalesDate. If your Date/Time field is named something else, such as invoice_date, substitute that name in the DatePart expression:
DatePart("m", [invoice_date]) = 12
For March instead of December invoices, use this:
DatePart("m", [invoice_date]) = 3
You could also use Month() instead of DatePart to get the same result:
Month([invoice_date]) = 3

SSRS expression Year and Month only from Date field

How do I build an expression in SSRS that only captures the Month and Year and not the day from a datestamp field?
I am trying to create a Month To Date column in SSRS. I have a date timestamp field, I also created a Month field and a Year field in hopes of solving my own problem. I didn't.
I have an expression built that allows me to capture the month and it works, but in my data set I have July data for both 2013 and 2014. This expression I only want to capture 2014.
=Count(IIF(Fields!Date_Month.Value = Month(Today()), Fields!AcctNo.Value, Nothing),
"Eligibility")
and I got it to work for the Year:
=Count(IIF(Fields!Year.Value = Year(Today()), Fields!AcctNo.Value, Nothing),
"Eligibility")
Can I somehow combine the 2 expressions? Should I?
Orrrrrrrrrr
I have tried to use my datestamp field to no avial: I get #Error with this abomination
=Count(IIF(Fields!Datestamp.Value = Month(Today()), Fields!AcctNo.Value,
Nothing), "Eligibility")
I'd think the preferred way is to use my above datestamp field and parse out the month and year. It's the way I'd do it....if I knew how to actually do it.
As you've suggested, you can combine the two expressions you have to get your required result with a few small changes:
=Count(IIf(Year(Fields!Datestamp.Value) = Year(Today)
and Month(Fields!Datestamp.Value) = Month(Today)
, Fields!AcctNo.Value
, Nothing)
, "Eligibility")
This will count all rows in the Dataset that have the same year and month as the current date.