Previous financial year - parameter expression for SSRS - reporting-services

I currently use:
=IIF(Today() >= DateSerial(Year(Today()), 4, 1),DateSerial(Year(Today()), 4, 1), DateSerial(Year(Today()) - 1, 4, 1))
and
=DATESERIAL(Year(Now()) + (IIF(format(now(),"MMdd") > "0331",1,0)) ,3,31)
to get me the current financial year (UK) dates, eg 1/4/2020 - 31/3/2021
Please can you advise how I'd adapt these to bring through the previous financial year, e.g:
1/4/2019 - 31/3/2020 ?
Many thanks

After putting my brain into gear I worked this out:
From date:
=DATESERIAL(cstr(Year(today())-1) - (IIF(format(now(),"MMdd") > "0331",0,1)) ,4,1)
To date:
=DATESERIAL(cstr(Year(Now())-1) + (IIF(format(now(),"MMdd") > "0331",1,0)) ,3,31)

Related

Access VBA - After Update Event

Need Assistance in generating a specific value to display on a form using vba on a Microsoft Access Form depending on how many combo boxes have a name.
For example if the User selects, 'Tom' the project will cost 10, if Tom and Jerry are selected then 20, if Tom Jerry and George then 30. So I want 'some other field' to populate a fixed amount based on how many of these combo boxes have values.
Please assist and thank you!
X = 10 * (7 - (Abs(IsNull(Me!txtTestDirector.Value)) + Abs(IsNull(Me!txtSystemOperator.Value)) + Abs(IsNull(Me!txtTestEngineer1.Value)) + Abs(IsNull(Me!txtTestEngineer2.Value)) + Abs(IsNull(Me!txtAnalyst.Value)) + Abs(IsNull(Me!txtTrainee1.Value)) + Abs(IsNull(Me!txtTrainee2.Value)))
Try with:
Value = 10 * (TotalCoboboxCount - (Abs(IsNull(Me!Combobox1.Value)) + Abs(IsNull(Me!Combobox2.Value)) + ... + Abs(IsNull(Me!ComboboxN.Value))))

Multiple Or in an IIF function

Given this data: Complete Dataset
I only want to get the Total_AR of those TransactionYrMonth=ParameterPeriod so I produced it using this code:
=IIF(
IsNothing(Sum(Fields!Total_AR.Value)),0,
Sum(IIF(Cdate(Fields!TransactionYrMnth.Value)=Cdate(Parameters!Period.Value),
Fields!Total_AR.Value,0)
)
)
From there, I got this dataset:
Filtered Dataset
Now, what I need to do is to get the sum of the first 3 service months starting from January to March that is equal to the latest transaction month which is April.
So the sum should be equal to $204,329 + -$96,640 + -$259,008 = -$151,319
To make it possible, I tried to use a code like this:
=Sum(IIF(
Cdate(Fields!TransactionYrMnth.Value)=Cdate(Parameters!Period.Value) And (
Cdate(Fields!ServiceYrMnth.Value)=DateAdd(DateInterval.Month, -3, CDate(Parameters!Period.Value)) Or
Cdate(Fields!ServiceYrMnth.Value)=DateAdd(DateInterval.Month, -2, CDate(Parameters!Period.Value)) Or
Cdate(Fields!ServiceYrMnth.Value)=DateAdd(DateInterval.Month, -1, CDate(Parameters!Period.Value))), Fields!Total_AR.Value,0
))
I have no luck producing it. I even got an error saying
‘Textbox11.Paragraphs[0].TextRuns[0]’ contains an error: [BC30516] Overload resolution failed because no accessible 'IIf' accepts this number of arguments.
Anyone, please help?
I got a solution already using this code:
=Sum(IIF(
Cdate(Fields!TransactionYrMnth.Value)=Cdate(Parameters!Period.Value) And
CDate(Fields!ServiceYrMnth.Value) >= DateAdd(DateInterval.Month, -3, CDate(Parameters!Period.Value)) And
CDate(Fields!ServiceYrMnth.Value) <= DateAdd(DateInterval.Month, -1, CDate(Parameters!Period.Value)), Fields!Total_AR.Value, 0
)
)

SSRS TimeFormat to 00:00:01

I have been struggling with a time format issue in SSRS. What I have so far is that seconds are listed with 00:00:15 but minutes like 15:25 instead of 00:15:25. I’ve been playing with it for a while now, but somehow it won’t show, no matter where I put the "00:" &
This is my code
=IIF(Sum(Fields!ActualTime.Value)/Fields!EventCount.Value < 1,"", IIF((Sum(Fields!ActualTime.Value)/Fields!EventCount.Value)/60 < 1, "00:00:" & (Sum(Fields!ActualTime.Value)/Fields!EventCount.Value), IIF((Sum(Fields!ActualTime.Value)/Fields!EventCount.Value)/3600 >= 1, ((Sum(Fields!ActualTime.Value)/Fields!EventCount.Value) - (Sum(Fields!ActualTime.Value)/Fields!EventCount.Value) mod 3600)/3600 & ":","") & IIF((Sum(Fields!ActualTime.Value)/Fields!EventCount.Value) mod 3600 >= 1, ((Sum(Fields!ActualTime.Value)/Fields!EventCount.Value) mod 3600 - (Sum(Fields!ActualTime.Value)/Fields!EventCount.Value) mod 3600 mod 60)/60 & ":","") & (Sum(Fields!ActualTime.Value)/Fields!EventCount.Value) mod 3600 mod 60))
Also 1 second, minute or hour is listed without a leading 0. Like this: 01:01:01
Please advise. Thanks in advance.
You can set the time format through the expression for a text fields. Click on the textbox and press f4. Go to the format and click on the dropdown and then click on expression.
In the expression u can write something like this.
=switch("More than one hour","HH:mm:ss",
"less than one hour and more than a minute","MM:ss",
"Less than one minute","SS",)
U have to put ur conditions in the part where I have mentioned the times ('more than one year etc.').
let me know if still ur facing any problems.
I couldnt get this to work. So after searching the web for a few days, i found a Function here on stackoverflow that converts seconds to hh:mm:ss. Since there where 16 fields that needed this calculation i found it easier to use this Function.
Thanks for the answer anyways.
Public Function ConvertSecondsToHourMinSec(ByVal intTotalSeconds) As String
Dim hours As String = INT(intTotalSeconds / 3600)
If Len(hours) < 2 Then
hours = RIGHT(("0" & hours), 2)
End If
Dim mins As String = RIGHT("0" & INT((intTotalSeconds Mod 3600) / 60), 2)
Dim secs As String = Right("0" & INT((intTotalSeconds Mod 3600) Mod 60), 2)
ConvertSecondsToHourMinSec = hours & ":" & mins & ":" & secs
End Function
In the textbox check for < 1 to show nothing and run the custom function otherwise.
=IIF(Sum(Fields!DownTime.Value)/Fields!EventCount.Value < 1,"",Code.ConvertSecondsToHourMinSec(Sum(Fields!DownTime.Value)/Fields!EventCount.Value))

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