I am using Microsoft Business Intelligence Development Studio 2012 trying to create a calculated field that will give me the Month and Week number of a field with the name 'createdon'.
I am new to SQL and after some research this is the code that I have come up with.
=Format(Fields!createdon.Value, "MMMM") & " Week " & (Int(DateDiff("d",DateSerial(Year(Fields!createdon.Value),Month(Fields!createdon.Value),1), Fields!FullDateAlternateKey.Value)/7)+1).ToString
But I am getting the error:
"The Field expression for the dataset 'Dataset1' refers to the field
'FullDateAlternateKey'. Report item expressions can only refer to
fields within the current datasetscop or, if inside an aggregate, the
specified dataset scope. Letters in the names of fields my use the
correct case.
I know this means that "FullDateAlternateKey" is not a valid field name, but I do not know what field name to substitute instead to correct this expression. Does anyone with more experience have any ideas as to how I can correct this?
Ideally, I would like it formatted to have a column that shows "week ending in ".
So any dates from 9/26/2015 to 10/2/2015 would say "Week of 10/2/2015"
Try this:
="Month: " & Datepart("m", Fields!createdon.Value) & " Week: " &
Datepart(DateInterval.WeekOfYear,Fields!createdon.Value)
You will get the following: Month: 10 Week: 43
Edit your question and add a example of the desired result in order to help you with the specific format.
Update:
Try this:
="Today: " & Format(Fields!createdon.Value,"dd/M/yyyy") & "Week Of: " & Format(
DATEADD("d" ,7-DATEPART(DateInterval.WeekDay,Fields!createdon.Value,FirstDayOfWeek.Monday),Fields!createdon.Value),
"dd/M/yyyy")
It will show: Today: 19/10/2015 Week Of: 25/10/2015
Related
I am trying to count the number of records in a table which satisfy criteria for two different fields. Both fields are string values.
The first field is what type of Test appears e.g. 'Manometry'. I can get this field to work on it's own.
I experience a problem when trying to add the second criteria.
The second field is the TestID, which is in the format A_155_19, where 155 is the investigation number and 19 identifies the year it took place.
I would like to count all the manometry tests which occur in the current year.
DCount("[Test]", "Visits", "[Test] = 'Manometry'" & "[TestID] = *Right((Year(Date)), 2)'")
I am currently getting the error message 3075, which is missing syntax.
Any help would be greatly appreciated.
What about:
DCount("[Test]", "Visits", "[Test] = 'Manometry' And [TestID] Like " & SomeExpression)
You can use Format:
DCount("*", "Visits", "[Test] = 'Manometry' And [TestID] Like '*_' & Format(Date(), "yy") & "'")
I am creating a simple report in SSRS
One of the fields is an address, which has this expression value
=First(Fields!BILL_CITY.Value) & ", " & Fields!BILL_PROV.Value & " " & Fields!BILL_ZIP.Value
What I want to do, is within that expression within SSRS, I want to add a condition.
If the Fields!BILL_ZIP.Value is only 5 digits, do nothing.
If the value is more than 5 digits, add a dash after the fifth digit.
So if customer sends the shorthand version of the zipcode it will appear as
45040 but if he sends the long version, it will be 45040-8999
Does anybody know how to do this? Creating the condition probably wouldn't be too hard, but how do I put it within the SSRS expression format?
Try:
= IIF(LENGTH(Fields!BILL_ZIP.Value) = 5, Fields!BILL_ZIP.Value & "-", Fields!BILL_ZIP.Value)
I need to display a text date like " August, 2018" if it is coming like "08-02-2018".
So, I have written this
" MONTHNAME(MAIL_DATE + 12 DAYS)||', '||YEAR(MAIL_DATE + 12 DAYS) as DateInText " wherein MAIL_DATE is today's date.
And, I have mapped in Birt like row["DateInText "], but I am not getting the value as expected like "August, 2018" .
You can make use of in built BIRT functions to achieve this.
In the detail row of the table, right click on the cell and go to "Edit Value/Expression.."
In the expression you can try this :
BirtDateTime.month(new Date(dataSetRow["DateInText"]),2) + ", " + BirtDateTime.year(new Date(dataSetRow["DateInText"]));
I hope this works.
Thank You
I have to write again this problem. I am not an expert in SSRS.
I have been trying to resolve this issue. Even though the fields are all the same datatype am still getting error and incorrect time difference in the filed in some fields.
I do not know what am doing wrong. This is the code. Please find below screen shot also.
enter code =Datediff(DateInterval.Minute, Fields!health_start_date.Value, Lookup(Fields!flight_date.Value & Fields!register_number.Value & DATEPART(DateInterval.Hour,Fields!health_start_date.Value) , Fields!FL_DATE.Value & Fields!REG.Value & DatePart(DateInterval.Hour, Fields!ATD.Value), Fields!ATD.Value, "DataSetAIMS") ) MOD 60 & " mins "
here
The scenario is that the two fields Health start date and ATD have two different dataset which shows time of flight differently but the time difference is always in minutes. What am trying to do is to compare the two table with their hour and date using lookup to find difference in minutes
Okay, I think I see the problem: you're really close and this stuff trips us all up on occasion. In the LOOKUP function, I think you are joining the two data sets based on:
flight_date = FL_DATE, and
register_number = REG, and
HOUR(health_start_date) = HOUR(ATD)
Which is fine, but the ampersand (&) just "concatenates" strings together, and (a) your strings don't actually match, and (b) HOUR is a number, not a string.
(a) The "date" in the first data set is DDMMYYYY, and in the 2nd it is DDMMYY. I.e., "05222018" is not the same as "052818", so your lookup will not work. It's possible that they are stored correctly as date fields in the database and so the comparison will work fine, but better to force them to match. For that I'd recommend formatting each of the date strings into a standard format, like "FormatDateTime(Fields!flight_date.Value, DateFormat.VBShortDate)".
(b) Should be easy, just add ".ToString" after the parentheses, like "DATEPART(DateInterval.Hour,Fields!health_start_date.Value).ToString()".
(c) I'm assuming the register_number and REG are formatted the same.
Given all that, your new LOOKUP function might look something like this:
=Datediff(DateInterval.Minute,
Fields!health_start_date.Value,
Lookup(
FormatDateTime(Fields!flight_date.Value, DateFormat.VBShortDate) & Fields!register_number.Value & DATEPART(DateInterval.Hour,Fields!health_start_date.Value).ToString() ,
FormatDateTime(Fields!FL_DATE.Value, DateFormat.VBShortDate) & Fields!REG.Value & DatePart(DateInterval.Hour, Fields!ATD.Value).ToString()
, Fields!ATD.Value
, "DataSetAIMS")
).ToString() & " minutes"
However, I think you'd make your life easier by just doing that sort of calculation in the database layer, in the report query, something like:
SELECT
d1.FlightDate
, d1.RegisterNumber
, d1.HealthStartDate
, d2.ATD
, DiffInMinutes = DATEDIFF(MINUTE, d1.HealthStartDate, d2.ATD)
FROM DataSet1 d1
JOIN DataSetAIMS d2
ON CAST(d1.FlightDate AS DATE) = CAST(d2.FL_DATE AS DATE)
AND d1.register_number = d2.REG
AND DATEPART(HOUR, d1.health_start_date) = DATEPART(HOUR, d2.ATD)
This code certainly isn't exact, but hopefully it will get you pointed in the right direction!
Thanks Russel. I have accepted your answer. What I did was to remove the formatdate from the expression code and modify the query design code to convert to the same time date : the code below
=Datediff(DateInterval.Minute, Fields!health_start_date.Value, Lookup(Fields!register_number.Value & DATEPART(DateInterval.Hour,Fields!health_start_date.Value).ToString() , Fields!REG.Value & DatePart(DateInterval.Hour, Fields!ATD.Value).ToString(), Fields!ATD.Value, "DataSetAIMS") ).ToString() MOD 60 & " mins "
or the below as well works :
=Datediff(DateInterval.Minute,
Fields!health_start_date.Value,
Lookup(
Format(Fields!flight_date.Value, "ddMMyy") & Fields!register_number.Value & DATEPART(DateInterval.Hour,Fields!health_start_date.Value).ToString() ,
Format(Fields!FL_DATE.Value, "ddMMyy") & Fields!REG.Value & DatePart(DateInterval.Hour,Fields!ATD.Value).ToString()
, Fields!ATD.Value
, "DataSetAIMS")
).ToString() MOD 60 & " minutes
I'm writing a query in Access 2013. The query will use the parameters from a form, pass those parameters to the query, and then display the results. I almost have it working. The problem with this form is that there are multiple date fields. There are two text fields (txtFromDate and txtToDate).
The idea is that user can enter date range one of two ways:
the user can click the date picker and select a date range to pass to the query;
the user can choose the Fiscal Year from a combobox.
I have created a separate table that is setup as follows:
Table: tbl_FiscalYear
Columns: FiscalYr_ID, FiscalYearName, FromDate, ToDate
In my query, the results work great (all parameters passed to query) if the user enters the manual dates in the txt fields. However, if they bypass the manual date entry and use the Fiscal Year combobox, the query results ignore all previous parameters and the results only reflect the appropriate date range per the Fiscal Year date setup in the fiscal year table.
I think the culprit is the OR statement at the end. Is there a way to incorporate both date search parameters into the form, and allowing the use of one or the other? Is my code not correct since it doesn't allow passing null values from the text date fields?
SELECT tbl_QUOTE.QUOTE_ID,
tbl_QUOTE.QUOTE_DATESTART,
tbl_QUOTE.QUOTE_DATEEND,
tbl_QUOTE.QUOTE_lookup_POC_ID,
tbl_QUOTE.QUOTE_lookup_LOC_ID,
tbl_QUOTE.QUOTE_lookup_TRAINER_NAME,
tbl_QUOTE.QUOTE_lookup_STATUS_ID,
tbl_QUOTE.QUOTE_lookup_TRAINER_ID,
tbl_QUOTE.QUOTE_lookup_MODS_ID,
tbl_POC.POC_AGENCY_lookup,
tbl_QUOTE.QUOTE_FINANCIAL_CD,
tbl_FISCALYEAR.FISCALYEARNAME
FROM tbl_fiscalyear, tbl_QUOTE
INNER JOIN tbl_POC ON tbl_QUOTE.QUOTE_lookup_POC_ID = tbl_POC.POC_ID
WHERE Nz([QUOTE_lookup_STATUS_ID],"") Like [Forms]![frm_QuoteReport]![cboStatusLookup] & "*"
AND Nz([tbl_POC].[POC_AGENCY_lookup],"") Like [Forms]![frm_QuoteReport]![cboAgency] & "*"
AND Nz([QUOTE_lookup_POC_ID],"") Like [Forms]![frm_QuoteReport]![cboPOC] & "*"
AND Nz([QUOTE_lookup_MODS_ID],"") Like [Forms]![frm_QuoteReport]![cboCourse] & "*"
AND Nz([QUOTE_lookup_LOC_ID],"") Like [Forms]![frm_QuoteReport]![cboLocation] & "*"
AND Nz([QUOTE_lookup_Trainer_ID],"") Like [Forms]![frm_QuoteReport]![cboTrainer] & "*"
AND Nz([Fiscalyr_ID],"") Like [Forms]![frm_QuoteReport]![cboFY] & "*"
AND Nz([Quote_Financial_Cd],"") Like [Forms]![frm_QuoteReport]![chkFundCd] & "*"
AND [QUOTE_DATESTART] Between [Forms]![frm_QuoteReport]![txtFromDate]
And [Forms]![frm_QuoteReport]![txtToDate]
OR [QUOTE_DATESTART]
BETWEEN (SELECT [tbl_fiscalyear].[fromdate]
FROM tbl_fiscalyear
WHERE fiscalyr_ID = [Forms]![frm_QuoteReport]![cboFY])
AND (SELECT [tbl_fiscalyear].[todate]
FROM tbl_fiscalyear
WHERE fiscalyr_ID = [Forms]![frm_QuoteReport]![cboFY]);
I believe I resolved it. I edited the final lines as follows:
OR [QUOTE_DATESTART] Between [Forms]![frm_QuotesReports]![txtFromDate]
And [Forms]![frm_QuotesReports]![txtToDate] <br/> AND [QUOTE_DATESTART]
BETWEEN (SELECT [tbl_fiscalyear].[fromdate] FROM tbl_fiscalyear WHERE
fiscalyr_ID = [Forms]![frm_QuotesReports]![cboFY]) AND (SELECT
[tbl_fiscalyear].[todate] FROM tbl_fiscalyear WHERE fiscalyr_ID = [Forms]!
[frm_QuotesReports]![cboFY])