conditional formatting by date - reporting-services

I have the following table in my report
Address SeenDate
stack street 2015-01-02
over lane 2016-03-15
flow way 2017-05-12
I would like to highlight addresses in green that have got a 'SeenDate' within 12 months, I think this will need to be a rolling 12 months. So from the table above 'flow way' will be highlighted in green.

To do a conditional on your date value to highlight records that are within 12 months of the report execution date, you can compare the date value with a year ago from today using iif in the Fill expression of the textbox:
=iif(Fields!SeenDate.Value >= Today().AddYears(-1), "Green", "Red")
Also a note to add that Today gives you the date for today and Now gives you the date and time of right now, depending on how precise you want to be.

Related

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.

write a condition in SSRS as specified

I am trying to find out how can I write the below logic in SSRS:
The structure of my report is:
All the rows and columns are grouped together.
The New Week Status has 2 fields: Current Week and Previous Week.
Current Week ranges from 30th Jan - 5th Feb
Previous Week ranges from 23th Jan - 29th Feb
The Gross Sales is in %.
I need to display only those restaurants where at least 5 days in Current Week and Previous Week is above 2% Gross.
Example:
In the above example, R1 has more than 5 days > 2%, so it will be displayed
R2 has less than 5 days > 2%, so it won't be displayed
How can the logic be implemented for this?
If you are not calculating the Gross Sales in the report this could work for you.
Select the whole Restaurant row and right click it, select Row Visibility... option:
Select Show or hide based on an expression: and use this expression:
=IIF(SUM(IIF(Fields!Gross_Sales.Value> 0.02,1,0))>=5,False,True)
Now only rows with at least 5 dates that have more than 0.02 (2%) Gross Sales are visible.
UPDATE: Adding examples.
I've recreated your dataset and the matrix, so having this structure:
Using the expression I posted above it hides the R2 row as expected.
UPDATE:
=IIF(
SUM(IIF(Fields!Total_Cost.Value/Fields!Sales_Gross.Value>0.02,1,0))>=5
or
SUM(IIF(Fields!New_Week_Status.Value = "Current Week" and Fields!Total_Cost.Value/Fields!Sales_Gross.Value>0.02,1,0))>=3
,False,True)

SQL division by a time frame

Have an RDB with a quantity x and the date that quantity started being tracked, date_1 and the date it was finished being tracked date_2. If tracking is still on going that second date is NULL obviously.
What I would like to do is take the number X and get its average over either date_1 and date_2. And if date_2 is NULL then go by current time. Any help?
[EDIT] to clarify in RDB format, one row with data column (x), data column (date_1) and data column (data_2) along with other fields of importance.
[EDIT] so imagine X as some integer like 100,000 and dates being March 30, 2016 12:29:45 and April 3, 2016 03:42:29. Not sure how to breakdown the date/times yet so open to suggestions. The end goal is calculate how much of x can be allocated in one month vs how much in the other month. Depending on how fine grain you breakdown the time frame (days vs seconds) will ultimately change those numbers.

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

get data for the year within from and to dates

I have the following query which gets year,Sum data between from and to date.
It works perfectly.
SELECT strftime('%Y',Date), SUM(Amount)
from table where (Date between '2008-08-01' and '2012-07-31')
GROUP BY strftime('%Y',Date)
I am displaying the sum on a bar chart.
Now If I click on the respective year it should show all the transactions till the "To Date" for that year or if the value is smaller than "To date" then the entire year's transaction.
For Eg: In the example above it displays Sum From Date : 2008-08-01 and To Date: 2012-07-31 .
If the user taps on the year 2012 bar column it should show transactions till the date 2012-07-31 and not for the entire year but if the user taps on 2011 it should transaction for the entire year as the TO Date is greater than 2011 year.
Same for the year 2008, it should display data from "2008-08-01" not the entire year and if I tap the bar column of that year it should show the transactions from that particular date till the end of the year and not for the entire year.
I have the query below which returns wrong value .
SELECT strftime('%Y',Date) ,*
from table where (Date between '2011-08-01' and '2012-07-31')
and strftime('%Y',Date)='2012'
GROUP BY strftime('%Y',Date)
This returns only one row for the date 2012-01-01 not all the values for the year 2012 till 2012-07-31.
Basically I would like to change only year in the following query and rest should be same. strftime('%Y',Date)='2012'
I don't know how to fix it or How to go about it w.r.t the above requirement.
Please help me fix it or Any Alternative. Thanks in Advance.
You don't need GROUP BY
SELECT strftime('%Y',Date) ,*
from table where (Date between '2011-08-01' and '2012-07-31')
and strftime('%Y',Date)='2012'