how to add #interval in a line chart ssrs - reporting-services

I was trying to add #interval in SSRS for my line chart, so the end user can select day, week, month from #interval. If the end used selects #interval = Week, the line will show only 1 number for every week, so the line will look nicer with less number.
I am thinking to create #interval in report parameters, then create expression for "chart data-values".
This was the expression I wrote, but it did not work.
=switch (Parameters!Interval.Value='Day', sum(Fields!DealPerActiveDealer.Value),
Parameters!Interval.Value='Month', Avg (sum(Fields!DealPerActiveDealer.Value)),
Parameters!Interval.Value='Week', Avg (sum(Fields!DealPerActiveDealer.Value))
Does anyone know how to work on this? Many Thanks!

I rarely use the Switch but the syntax looks correct. You should be using double quotes instead of single in an expression.
=SWITCH(PARAMETERS!INTERVAL.VALUE = "DAY", SUM(FIELDS!DEALPERACTIVEDEALER.VALUE),
PARAMETERS!INTERVAL.VALUE = "MONTH", AVG(SUM(FIELDS!DEALPERACTIVEDEALER.VALUE)),
PARAMETERS!INTERVAL.VALUE = "WEEK", AVG(SUM(FIELDS!DEALPERACTIVEDEALER.VALUE))
As to your chart, you might also need to change the axis with your time line. I assume it shows every day now but should be dynamic also. Your grouping expression would be something like:
=DATEPART(SWITCH(Parameters!Interval.Value = "Day", "d"
Parameters!Interval.Value = "Month", "m",
Parameters!Interval.Value = "Week", "ww"), Fields!DATEFIELD.Value)

Related

SSRS Conditional Formatting with 3 Colours

Trying to figure out conditional formatting for SSRS/Visual Studio and trying to get the figures to show this as an expression as follows;
Below benchmark needs to be Red
Above but within 5% needs to be Gold
More than 5% above needs to be Green
Benchmark 60%
Year 1 62.2%
Year 2 67.4%
Year 3 43.6%
First time in writing something like this so unsure what the best step is!
=iif("Textbox83" > "Textbox82", "SpringGreen", iif("Textbox83" < "Textbox82", "Red", iif("Textbox83" = "Textbox82" + 0.05,"Gold", "Transparent")))
A few things here..
Use SWITCH rather than nested IIFs, it much easier to read and debug.
You would normally work against the dataset fields rather than the textboxes displayed on the rendered report. If you do refence the textboxes, you probably have to convert the values to numeric before comparison
If you reference an object, either a dataset field or an rendered textbox, you must state the property you want, typical .Value
If this was being done against dataset fields you would do something like this
=SWITCH (
Fields!myValue.Value < Fields!Benchmark.Value, "Red",
Fields!myValue.Value <= (Fields!Benchmark.Value * 1.05), "Gold",
Fields!myValue.Value > (Fields!Benchmark.Value * 1.05), "Green",
True, Nothing
)
Switch stops at the first expression that results in True so the sequence of conditions is important. The final expression pair True, Nothing acts like an ELSE and returns nothing (which is the default backgroundcolor property, which appears as transparent)
If you wanted to replicate this using the textboxes (don't unless you really have to!) then it's basically the same but a bit more messy.
=SWITCH (
VAL(ReportItems!TextBox83.Value) < VAL(ReportItems!TextBox82.Value), "Red",
VAL(ReportItems!TextBox83.Value) <= (VAL(ReportItems!TextBox82.Value) * 1.05), "Gold",
VAL(ReportItems!TextBox83.Value) > (VAL(ReportItems!TextBox82.Value) * 1.05), "Green",
True, Nothing
)
The above is from memory and therefore untested but it should be OK.

Difference between two time values in SSRS report

I have the following select statement:
SELECT [TR_DATE]
,[TR_TIME]
,RIGHT('000000' + CONVERT(varchar,TR_TIME), 6)
,TIMEFROMPARTS(SUBSTRING(RIGHT('000000' + CONVERT(varchar,TR_TIME), 6),1,2), SUBSTRING(RIGHT('000000' + CONVERT(varchar,TR_TIME), 6),3,2), SUBSTRING(RIGHT('000000' + CONVERT(varchar,TR_TIME), 6),5,2),0,0) as trtime
,[ET_TYPENO]
,[ET_NAME]
FROM [DB400].[dbo].[TRANSACTIONREPORT]
where DEPT_NAME = 'GIJIMA AST HOLDINGS (PTY) LTD'
/*and LOC_NAME = 'Front Door and Gate'*/
and TR_DATE between '20200120' and '20200130'
order by TR_DATE, MST_LASTNAME, MST_FIRSTNAME, TR_TIME
which returns the following data:
I would like to use this to calculate the time the was spent in the building.
Note that ET_TYPENO = 1 equates to "Allowed Normal In" and ET_TYPENO = 2 to "Allowed Normal Out"
I have the following expression inside an ssrs report
=iif(Fields!ET_TYPENO.Value=2,
DateDiff(DateInterval.Hour, previous(Fields!trtime.Value),Fields!trtime.Value),
"")
But it resolves to the following #Error.
UPDATE
Expected Result
Calculate the time difference between the "Allowed Nornmal In" event and the "Allowed Normal Out" event.
Take line 2 and 3 for example. "Allowed Nornmal In" occured at 07:23:19 and "Allowed Normal Out" occured at 08:55:48. I need it to return the time difference between these two times. I.E. 1:32:29.
The trtime needs to be converted to a DATE type with the CDATE() function to use the DATEDIFF function.
=IIF(Fields!ET_TYPENO.Value = "OUT",
DateDiff(DateInterval.Hour, CDATE(previous(Fields!trtime.Value)), CDATE(Fields!trtime.Value)),
NOTHING)
Also, shouldn't Fields!ET_TYPENO.Value = 1 ?
Taking the suggestion from Honnover Fist's answer that the parameter of the DateDiff need to be Dates instead of Times. (The Documentation does say that a Time will work). I have changed my query to a DATETIMEFROMPARTS() instead of a TIMEFROMPARTS().
Then I changed the condition to the below code so that the hours would be displayed more accurately.
=IIF(Fields!ET_TYPENO.Value = 2,
DateDiff(DateInterval.Minute, previous(Fields!TR_DATETIME.Value), Fields!TR_DATETIME.Value) / 60,
NOTHING)

SSRS customized pie chart color

I have a doubt here,
I need to show a pie-chart in SSRS, for the student results according to their status(Pass/Fail).......I have only 4 conditions Male-pass,Male-fail,Female-pass,Female-fail,I need to show these things with my own color,
for this am using the switch condition as
=Switch(
((Fields!Gender.Value = "Male")&(Fields!Status.Value="Pass")), "Blue",
((Fields!Gender.Value = "Male")&(Fields!Status.Value="Fail")), "HotPink",
((Fields!Gender.Value = "Female")&(Fields!Status.Value="Fail")), "Orange",
((Fields!Gender.Value = "Female")&(Fields!Status.Value="Pass")),"LimeGreen" )
but in the preview it shows only the default color set, not the customized one, can anyone fix this one...thanks in advance
Try using something like
=IIf((Fields!Gender.Value = "Male") and (Fields!Status.Value="Pass"),"Green",
IIf((Fields!Gender.Value = "Male") and(Fields!Status.Value="Fail"),"Red" ,
IIf((Fields!Gender.Value = "Female") and (Fields!Status.Value="Fail") ,"Blue",
(Fields!Gender.Value = "Female") and (Fields!Status.Value="Pass"),"Yellow","Orange"
,"#00000000"))))
You should be able to get it working using the Switch statement as well. The problem with your expression is that the logical "and" operator in SSRS is And, not ampersand. In SSRS, a single ampersand is used for concatenating strings. So your expression is concatenating the string representation of the two boolean results, resulting in strings like TrueFalse. This should actually giving an error on the Switch evaluation.
A correct Switch statement would be this:
=Switch(
Fields!Gender.Value = "Male" And Fields!Status.Value="Pass", "Blue",
Fields!Gender.Value = "Male" And Fields!Status.Value="Fail", "HotPink",
Fields!Gender.Value = "Female" And Fields!Status.Value="Fail", "Orange",
Fields!Gender.Value = "Female" And Fields!Status.Value="Pass","LimeGreen"
, True, "SomeOtherColor"
)
I've also added an "else" part to the switch in case some records are not covered by the other conditions. If you're 100% sure that won't happen, you can remove the line that starts with "True". But it shouldn't hurt to keep it either.
More info: Pie Chart Techniques (look for Custom Coloring chapter)

Inherited database has leap year code that compiler doesn't like

In my job, I have inherited an Access 97 database. This database is very unstable and I need to remedy that in one way or another. I have been trying to go through and debug the current version so that I can migrate it to 2007. I have run across some code that the compiler doesn't like and not sure how to fix it...here is the code:
Function DaysInMonth(ByVal D As Date) As Long
' Requires a date argument because February can change
' if it's a leap year.
Select Case Month(D)
Case 2
If LeapYear(Year(D)) Then
DaysInMonth = 29
Else
DaysInMonth = 28
End If
Case 4, 6, 9, 11
DaysInMonth = 30
Case 1, 3, 5, 7, 8, 10, 12
DaysInMonth = 31
End Select
End Function
I get a compile error: Sub or Function not defined and it highlights the first "LeapYear".
Any help at all would be greatly appreciated! Thanks!
LeapYear is another function or procedure that appears not be present in your modules or has been made Private. LeapYear isn't a VBA function. There must have been a function that takes a year Year(D) and returns TRUE or FALSE if it's a leapyear. either insert one or set the existing one to Public
Edit:You could use IsLeapYear but change to 'LeapYear' and call using IsLeapYear(D)
The code in question is idiotic -- it was clearly written by somebody who didn't have a clue about VBA dates, which already know everything that is needed without needed to encode this crap into a CASE SELECT.
This expression will get you the number of days in a month:
Day(DateAdd("m", 1, DateValue(Month(Date()) & "/1/" & Year(Date()))) - 1)
What this does is get the first of the current month, adds a month to it (for the first of the next month), and then subtracts 1 from it. Since the integer part of the VBA date type is the day part, that will get you the last day of the current month. Then you take the result and pull the day out with the Day() function.
Coding that up as a function:
Function DaysInMonth(ByVal dteDate As Date) As Integer
Dim dteFirstOfMonth As Date
Dim dteLastOfMonth As Date
dteFirstOfMonth = DateValue(Month(dteDate) & "/1/" & Year(dteDate))
dteLastOfMonth = DateAdd("m", 1, dteFirstOfMonth) - 1
DaysInMonth = Day(dteLastOfMonth)
End Function
You could also code this up using the fact that the DateSerial() function treats the zeroth day as the last of the previous month:
Function DaysInMonth(ByVal dteDate As Date) As Integer
Dim dteOneMonthFromDate As Date
Dim dteLastOfThisMonth As Date
dteOneMonthFromDate = DateAdd("m", 1, dteDate)
dteLastOfThisMonth = DateSerial(Year(dteOneMonthFromDate), Month(dteOneMonthFromDate), 0)
DaysInMonth = Day(dteLastOfThisMonth)
End Function
But that doesn't make it any shorter...
None of this requires figuring out leap year rules -- those are built into the VBA date type.
And, of course, the function should not return a Long, but an Integer, since the maximum value it can ever return is 31.
LeapYear may not be your only issue.
In Access '97, go to the VBA editor and click "Tools/References":
Look in the references of your '97 project and see what DLLs are listed.
A screen will appear that shows you the ActiveX DLLs that can be used for the project. The ones that are checked are the ones currently used:
Odds are there is a DLL there that needs to be referenced in your new 2007 database.

Nested IIfs in reporting services

can anyone help please. I need to put an IIf within an IIf within an IIf. I have a parameter called 'Period' with 4 labels, '24 Hrs, 3 Days, 7 Days, Month'. I have another Parameter ('Date' and hidden) containing the following DateSerial
'=DateSerial( Datepart("YYYY",Now()),Datepart("m",Now()),Datepart("d",Now())-1 )'
which the parameter Period defaults to on opening e.g. 20/10/2009 07:00
The third Parameter ('Date From' also hidden) is where I want to put the nested IIfs. I want it to read from the Parameter 'Period' and depending on the selection will depend on outcome, my code so far looks like this (not completed yet as I want to see if the first two IIfs work:
'IIf(Parameters!Period.Value = 1, DateAdd("h", 7, Parameters!Date.Value),
IIf(Parameters!Period.Value = 2, DateAdd("h", -41, Parameters!Date.Value)))
Can anyone tell me where I am going wrong.
Regards, Althea
You need a "else" value in the second IIf just in case your Period is neither 1 nor 2:
=IIf(Parameters!Period.Value = 1,
DateAdd("h", 7, Parameters!Date.Value),
IIf(Parameters!Period.Value = 2,
DateAdd("h", -41, Parameters!Date.Value),
Parameters!Date.Value)) ' If period is neither 1 nor 2 just return the date