set databand filter based on variable value
Posted: Fri Jun 30, 2017 5:00 pm
Hello,
I am working on a report where user can choose to display data based on 1 of 2 date ranges - fiscal year or calendar year.
Fiscal Year runs from October 1 of one year to September 30 of the following year. I have "Fiscal Year" and "Calendar Year"
as options in a variable called rptReportPeriod and I have Request Parameters set to True for the report.
I can use expression A below in a Databand filter to limit information for the Fiscal Year or expression B. to limit the information for the Calendar year.
(rptYear is another variable that users can enter a year into).
A. WorkOrders.BeginDate >= DateTime.ParseExact("10/01/" + rptYear, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)
&& WorkOrders.BeginDate <= DateTime.ParseExact("09/30/" + (int.Parse(rptYear) + 1).ToString(), "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)
B. WorkOrders.BeginDate >= DateTime.ParseExact("01/01/" + rptYear, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)
&& WorkOrders.BeginDate <= DateTime.ParseExact("12/31/" + rptYear, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)
What I'd like to be able to do is use an IIF statement to apply the proper expression based on the rptReportPeriod variable. Something like...
IIF(rptPeriod == "Fiscal Year",
WorkOrders.BeginDate >= DateTime.ParseExact("10/01/" + rptYear, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture) && WorkOrders.BeginDate <= DateTime.ParseExact("09/30/" + (int.Parse(rptYear) + 1).ToString(), "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture),
WorkOrders.BeginDate >= DateTime.ParseExact("01/01/" + rptYear, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture) && WorkOrders.BeginDate <= DateTime.ParseExact("12/31/" + rptYear, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture))
The above expression doesn't work though - it gives a generic Error #2032 and the More Details button just says "Server Message is Empty".
Is there a way to do what I'd like - perhaps with the use of additional variables and the Begin Render events of the report and/or databand?
I am working on a report where user can choose to display data based on 1 of 2 date ranges - fiscal year or calendar year.
Fiscal Year runs from October 1 of one year to September 30 of the following year. I have "Fiscal Year" and "Calendar Year"
as options in a variable called rptReportPeriod and I have Request Parameters set to True for the report.
I can use expression A below in a Databand filter to limit information for the Fiscal Year or expression B. to limit the information for the Calendar year.
(rptYear is another variable that users can enter a year into).
A. WorkOrders.BeginDate >= DateTime.ParseExact("10/01/" + rptYear, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)
&& WorkOrders.BeginDate <= DateTime.ParseExact("09/30/" + (int.Parse(rptYear) + 1).ToString(), "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)
B. WorkOrders.BeginDate >= DateTime.ParseExact("01/01/" + rptYear, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)
&& WorkOrders.BeginDate <= DateTime.ParseExact("12/31/" + rptYear, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)
What I'd like to be able to do is use an IIF statement to apply the proper expression based on the rptReportPeriod variable. Something like...
IIF(rptPeriod == "Fiscal Year",
WorkOrders.BeginDate >= DateTime.ParseExact("10/01/" + rptYear, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture) && WorkOrders.BeginDate <= DateTime.ParseExact("09/30/" + (int.Parse(rptYear) + 1).ToString(), "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture),
WorkOrders.BeginDate >= DateTime.ParseExact("01/01/" + rptYear, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture) && WorkOrders.BeginDate <= DateTime.ParseExact("12/31/" + rptYear, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture))
The above expression doesn't work though - it gives a generic Error #2032 and the More Details button just says "Server Message is Empty".
Is there a way to do what I'd like - perhaps with the use of additional variables and the Begin Render events of the report and/or databand?