write a condition in SSRS as specified - reporting-services

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)

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.

conditional formatting by date

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.

Can I automatically change the dataset for a tablix based on the current month?

I have a report with 7 datasets and 7 tables all exactly the same except the datasets each have a slightly different where clause
where datepart(DW,[Start Time]) = 2
The idea is to show data for each monday this month in one table and each tuesday in another and so on. So one table uses the monday dataset (above) one uses
where datepart(DW,[Start Time]) = 3
for tuesday and so on. What I really want to do is have the report decide which dataset to use first based on what day the first of the current month was. So this month (April) the 1st was a saturday so I'd like my leftmost table to use the dataset
where datepart(DW,[Start Time]) = 7
Then the one after it to be sunday and so on. But next month (May) I want it to automatically switch to using the monday dataset in the first table as the 1st will be a monday.
Is this possible?
One possibility is to use a sub-report that uses a single dataset. This dataset would have a where clause that takes a parameter
WHERE DATEPART(DW, [Start Time]) = #dayOfWeek
Replace your current 7 tables with 7 copies of the same sub-report but change the parameters to be based on the first day of the month so you first sub-report would have the parameter passed as
=WeekDay(dateserial(Year(now()), Month(now()), "1"))
the second sub report would have the parameter passed as
=WeekDay(dateserial(Year(now()), Month(now()), "2"))
and so on...

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

Grouping months by quarter over multiple years depending on a dynamic start month

Using MySQL and PHP I am building a JSON array to populate a data table.
For the purposed of my question suppose the data table has the following columns:
Year: 2010,2011,2012,2013...<br/>
Month: 1,2,3,4,5...<br/>
Value: 100, 150, 200 etc...<br/>
The table structure cannot be altered and my solution needs come into the MySQL query
The data can be viewed either monthly, quarterly or yearly. Monthly and yearly is achieved easily through grouping by year and month.
Quarterly data can be grouped by calendar quarter (Jan-Mar, Apr-Jun, Jul-Sep, Oct-Dec) by this group statement:
GROUP BY year, round((month/3)+0.3,0)
So where Jan, Feb and March might all have 100 for their value the summed result is 300, same for other months.
Now my problem comes when I want to group values by a financial quarter, for example a quarter that starts in Feb, or any other quarters.
I have a statement that works for the quarter grouping using two variables that can be accessed via the SQL query, start_year (i.e. 2014) and start_month (i.e. 2)
GROUP BY year, (((round(((((month-(start_month-1))+((year-start_year)*12))-((year-start_year)*12))/3)+0.33,0)/4)+4)-floor(((round(((((month-(start_month, '%m')-1))+((year-start_year)*12))-((year-start_year*12))/3)+0.33,0)/4)+4)))*12
which basically will assign a 0,3,6,9 value to each calendar month for the purposes of grouping.
In the financial year starting February this works fine for quarters 1-3, however breaks for the final quarter as it includes Nov and Dec 2014 data and Jan from 2015.
As a result I get 5 rows of data instead of 4.
This is because of the preceding GROUP by year clause, an important addition as we might want to generate a table that views sequential quarters for multiple years.
So what I am looking for is a way of grouping the years together by offsetting the start month.
So when the year starts in Jan it will group Jan-Dec but if we change that to starting Feb it will group Feb-Jan.
Any ideas, suggestions most welcome!
Regards,
Carl
I solved a similar problem just now (a Moodle report aggregating assignment scores by year and quarter) with something like this:
select year(from_unixtime(s.timemarked)) as year, quarter(from_unixtime(s.timemarked)) % 4 + 1 as quarter, count(distinct data1) as "tickets graded" from mdlassignment_submissions s where grade >= 0 group by year, quarter order by year, quarter;
The relevant part for what you're doing is quarter(from_unixtime(s.timemarked)) % 4 + 1 as quarter
As another commenter pointed out, MySQL has a quarter() function, but it doesn't do financial quarters. However, since (as I understand it, at least, based on consulting the relevant wikipedia page) financial quarters are just offset by 1, the % 4 + 1 at the end should convert it.