Adding two date stamps into a single SSRS expression/cell - mysql

This is all done in Microsoft SQL Server Report Builder
So I have a large data set that contains Work orders and then their 'type/craft'. Each craft is then broken down into each row so that you can see how many work orders are still open in the certain craft. At the top of the page, It list, WO's 1-2 Past Due, WO's 3-5 Past Due, WO's 6-10 Past Due... etc, till you reach 30 days+
I then have an expression inserted that will tell you what date the 1-2 days is... However, I am having trouble making the expression value be 2 dates or an in between date.... For example, I have =DateAdd("d", -1, Now) inserted which will give me the date from 1 day back, however, I would ALSO like it to show 2 days back.... So instead of ONLY saying 6/13/2018... it would say 6/12/2018 to 6/13/2018
I guess I could go back and edit my SQL code to automatically do the dates, however I thought it would be easier to use the report system.

You would want your expression to be something like this:
=DateAdd("d", -2, Today()) & " to " & DateAdd("d", -1, Today())
If you need the time as well you would want to use Now instead of Today, but based on your question it seems you are only interested in the dates, so this should return exactly what you are looking for.

Related

Auto populate dates of the week Paginated reports

Good day
I am very very new two paginated reports so forgive me if this is a silly question
I have a report that displays values for Mondays to Fridays based on the date selected from a date picker.
So basically
You select a date (Example 24 Nov) and the following table is displayed based on values pulled from SQL.
Now my question is how do I display the dates of the weekdays too?
So if the date selected is Thursday 24 Nov, in the column headers under the week day names it should give the corresponding date i.e Monday-21/11/2022, Tuesday - 22/11/2022, etc.
Below is a little snippet of the data
So the date picker is based on the ReportingDate column. The rows of the matrix consist of Region and Country and the values are the sum of Monday-Friday.
Any guidance would be greatly appreciated.
Edit: The day names are not obtained via an expression in SSRS. They carry over from the column headers in the data set.
Assuming you have some expression to get the actual day name already, you can leave that bit as it is.
Now, double click the column header "cell"/textbox to get a cursor in there, then click at the end of the existing fields/expression.
Now just put a space in and then right-click and choose "Create Placeholder". The placeholder dialog will appear.
This placeholder acts almost like a separate textbox to you can put whatever you want in there, click the '[fc]' button next to the Value property and then set this to whatever you want, e.g. =Fields!ReportingDate.Value.
Now go to the "number" tab on the same dialog box and set the format to the required date format.
If you want to edit this later, just double click the cell again but this time right-click the placeholder and choose properties.
The other way of doing this would be to add another row to your header and set that to be the date instead but then you have to mess around removing borders etc., sometimes this can be easier if layout is an issue but you have a couple of options at least now.
I managed to figure it out with the help of the following post.
These are the steps I followed
Get the date of the first day of the current week (Sunday's date) using the formula explained in the link
DateAdd("d",1- DatePart("w", CDate(Parameters!ReportingDate.Value)), CDate(Parameters!ReportingDate.Value))
Use DateAdd to add the corresponding number of days to get to a required weekday. That is for Monday add 1, Tuesday add 2,...
DateAdd("d",1,DateAdd("d",1- DatePart("w", CDate(Parameters!ReportingDate.Value)), CDate(Parameters!ReportingDate.Value)))
Format datetime to date and add new line to insert date below day name
="Monday" + Environment.NewLine + FormatDateTime(DateAdd("d",1,DateAdd("d",1- DatePart("w", CDate(Parameters!ReportingDate.Value)), CDate(Parameters!ReportingDate.Value))), DateFormat.ShortDate)

Conditional formatting in a matrix

This is my matrix in design view
The Last column has the following expression in it. This brings back the latest date for that particular row.
=Format(Max(Fields!DateTime.value),"dd/MM/yyyy HH:mm:ss")
I want to colour the ones that have occurred within the last 6 weeks
=IIF(DateDiff(DateInterval.Day , Fields!DateTime.Value, Today()) <=42, "#f5c6c8", Nothing)
This brings back the following
For some reason it's working for some fields and not others
Right managed to figure this out, needed to put max in my expression
=max(IIF(DateDiff(DateInterval.Day , Fields!DateTime.Value, Today()) <=42, "#f5c6c8", Nothing))

Interesting SSRS parameter discovery when using subscriptions

I have recently been putting together an SSRS report that will run every 15 minutes for the previous 15 minute 'chunk' of time. In essence a very straight forward and simple report that will run via an automated subscription.
I was using Microsoft SQL Server 12 Report Builder Version 3.
I was alerted to an issue with the output csv when my recipient reported being sent blank files, most odd considering the report generated as expected when run manually.
Long story short, it was the expressions I was using to generate the From and To dates. Manual runs produced data, subscription runs did not.
Original parameters
FromDate
dateadd(DateInterval.Second, (second(now()) + 900) * -1, dateadd(Dateinterval.Minute, (minute(now()) mod 15) * -1, now()))
ToDate
dateadd(DateInterval.Second, (second(now()) + 1) * -1, dateadd(Dateinterval.Minute, (minute(now()) mod 15) * -1, now()))
New Parameters
FromDate
dateadd(DateInterval.Minute, -15, dateadd(DateInterval.Minute, cint(datediff(DateInterval.Minute,today(),now()) / 15) * 15, today()))
ToDate
dateadd(DateInterval.Second, 899,Parameters!FromDate.Value)
Thought I would post this here for two reasons
Theories as to why
It might help someone in the future
Your original parameters take Now and subtract the minutes to arrive at a 15-minutes time, then they take the seconds of another Now (which is later and could be in the next second or even minute) and subtract that value to arrive at a 0-second time (or a 59-second time). This could already cause a problem when there is a change of seconds between the first and the second Now, which isn't very unikely, as on my test system there were 0.59 seconds between the two evaluations of Now in the FromDate parameter. Also, the Now value is more accurate than just a second, and your formula does not respect that. Therefore, if the records you are trying to process in your report happen to have a time of exactly a quarter of an hour, the first parameter is for sure greater (by maybe 0.01 second) and so the record is ignored.
Your formula for the "new parameters" does not depend on the seconds of Now() and will always return a time with no fraction of a second, so I guess that that's what makes the difference.
The expression for the FromDate could be simplified a little:
=Today.AddSeconds(900*(DateDiff(DateInterval.Minute, Today, Now)\15-1))
If you do not plan to run the report very short before midnight, there should not be a problem caused by a change of the day during the evaluation of Today and Now, and you could calculate the second parameter in a similar way, independently from the first one:
=Today.AddSeconds(900*(DateDiff(DateInterval.Minute, Today, Now)\15)-1)
The original parameter values were being calculated individually which means they would each have slightly different values for Now(). I know this is a long shot, but it's a theory. If the subscription job fired off a fraction of a second before a 15 minute interval, it's possible that the ToDate returned just before the FromDate. This would result in an invalid date range.
With the new expressions, the ToDate is referencing the FromDate which forces them to be calculated in sequence, not in parallel. Not to mention you're adding to the FromDate which also forces the date range to have a consistent length. However, you may still run into a case where you get the same report twice if the FromDate is calculated on the wrong side of a 15 minute cutoff.
One way to test/avoid this issue would be to offset the subscription time so that it doesn't actually try to fire at the exact 15 minute cutoffs. For example, you could have it scheduled to go off 1 minute afterwards.

Need Savings totals by month to pull data correctly and display in Chart

My data and this SSRS chart have a ton of problems, I'll try to keep my question(s) succinct.
First, as you can see by this chart and this screenshot of my data (just showing date and April Savings), my expression/chart is not summing all of the savings within a month, which is my goal.
It appears to be picking one amount within the correct month and using it. I set up a tool tip for April so I could see what number it's pulling (since clearly the chart columns are not representing the data whatsoever - another issue).
You'll see in the SQL data screenshot that it does indeed pull $1,230 from the April 2013 Savings. How can I get this to Sum within the month AND still do a running value from the beginning of time data began to current, this often will include multiple years.
Here's my Chart Data (note that my Team Goal works perfectly, and is even charted correctly - but if anyone knows how to force that line to go from end to end on my chart, feel free to let me know.) :
To summarize, how can I sum each month's data, while still do a running value across the months AND years?
Here's my Expression for Implementable Savings:
=RunningValue(Sum(Fields!ImplementableSavings.Value), Sum, nothing)
(obviously if I can get one working, I can get both)
My Expression for ImplementedSavingsMonth:
=MonthName(Month(Fields!ImplementedSavingsDate.Value))
My Expression for ImplementedSavingsYear:
=Year(Fields!ImplementedSavingsDate.Value)
Let me know if there's anything else I can provide.
Quick sidebar question: WHY does my chart column collect one piece of data. IE: see the tool tip $1,230 for April 2013), but the chart column displays that the number is around $1.7M? And in this scenario, both of my blue and yellow columns are displaying the same number, so why does blue always appear to be a higher number? I will ask this as a 2nd question if it's inappropriate for me to ask here.
I would use this Expression for Implementable Savings:
= RunningValue ( Fields!ImplementableSavings.Value, Sum, "Chart1")
.. assuming your Chart's name is Chart1.

Past 5 week calculation in WEBI (BO 4.0)?

I am facing issue in calculating past 5 week data based on current date (excluding currrent week)
For e.g:
Suppose we are in 40th week of this year, I need to get the sum of all the transactions for the previous 5 weeks (39, 38, 37, 36 & 35).
Currently calculating based on the calendar day but as Calendar day is giving the granular level of data, inorder to increase the performance I need to use the calendar week (sample data like (2012/40).
Is there a way to do this?
I'd construct a flag field (either in the back-end or in the universe) using datediff (in SQL Server terms).
Failing that, you could construct a variable in Web Intelligence using the Week function.
Pseudo-code but something like:
=IF(Transaction_Date < Week(CurrentDate()) AND Transaction_Date >= (Week(CurrentDate())-5); "TRUE"; "FALSE")