SSRS Expression inversed return - date

So I have an expression that calculates the number of weekdays between two dates (excluding these dates). But the expression seems to give the opposite results of what I want and I don't know why. Here's the expression:
=iif(IsNothing(Fields!End_Date.Value) or IsNothing(Fields!Report_Submitted_Date.Value) or Fields!Report_Submitted_Date.Value>Fields!End_Date.Value,"Invalid Data",
(DateDiff(DateInterval.day,Fields!End_Date.Value,Fields!Report_Submitted_Date.Value)+1)
- (DateDiff(DateInterval.WeekOfYear,Fields!End_Date.Value,Fields!Report_Submitted_Date.Value)*2)
- IIF(Weekday(Fields!End_Date.Value,1) = 1,1,0)
- IIF(Weekday(Fields!End_Date.Value,1) = 7,1,0)
- IIF(Weekday(Fields!Report_Submitted_Date.Value,1) = 1,1,0)
- IIF(Weekday(Fields!Report_Submitted_Date.Value,1) = 7,1,0)-2)
So, the result I get from this expression is that every situation where the End Date is smaller than the Report Submitted Date I get the text Invalid Data and the rest are #Error or negative numbers.
Now I know I can solve this by switching the True and False clause but I would like to understand why these results are switched because for as far as I can read:
IF End Date OR Report Submitted Date are null
OR IF End Date is bigger than Report Submitted Date I should get the Invalid Data text.
Any answers are appreciated.
EDIT 1:
So I have changed the expression from an IIF to a switch.
=switch(
IsNothing(Fields!End_Date.Value),"Invalid Data",
IsNothing(Fields!Report_Submitted_Date.Value),"Invalid Data",
Fields!Report_Submitted_Date.Value <= Fields!End_Date.Value, "Invalid Data",
True, "Good Data"
)
And this gives me the results that I expect, however, if I change Good Data with my expression to calculate the difference of weekdays between the two dates I still get a #Error. It looks like when I do this it doesn't recognize the Report Submitted Date as Nothing. Altered expression below:
=switch(
IsNothing(Fields!End_Date.Value),"Invalid Data",
IsNothing(Fields!Report_Submitted_Date.Value),"Invalid Data",
Fields!Report_Submitted_Date.Value <= Fields!End_Date.Value, "Invalid Data",
True, ((DateDiff(DateInterval.day,Fields!End_Date.Value,Fields!Report_Submitted_Date.Value)+1)
- (DateDiff(DateInterval.WeekOfYear,Fields!End_Date.Value,Fields!Report_Submitted_Date.Value)*2)
- IIF(Weekday(Fields!End_Date.Value,1) = 1,1,0)
- IIF(Weekday(Fields!End_Date.Value,1) = 7,1,0)
- IIF(Weekday(Fields!Report_Submitted_Date.Value,1) = 1,1,0)
- IIF(Weekday(Fields!Report_Submitted_Date.Value,1) = 7,1,0)-2)
)
Result:

Related

Date logic in DAX

I am trying to compute a percentage difference between two values - market index levels separated by a period of time (the period will be determined by user input in a Power BI Slicer tool). I don't understand how I can cross reference values DAX uses by the associated date.
Value % difference from Value =
VAR __BASELINE_VALUE = SUM('Equity Markets (2)'[Value])
VAR __VALUE_TO_COMPARE = SUM('Equity Markets (2)'[Value])
RETURN
IF(
NOT ISBLANK(__VALUE_TO_COMPARE),
DIVIDE(__VALUE_TO_COMPARE - __BASELINE_VALUE, __BASELINE_VALUE)
)
"Value" is a column in a table "Equity Markets (2)" the table also includes a "Date" column.
What is the syntax for selecting a value from Value based on an associated date?
Apologies for asking such a basic question - feels like 30 sec of googling should have done it for me.
The slicer is engaging with the bar graph correctly - I know becouse I'm measuring the levels. I think all the % changes are zero because I'm evaluating x/x -1
percentage change =
VAR
__EarliestValue = CALCULATE(SUM('Equity Markets (2)'[Value]),
FIRSTDATE('Equity Markets (2)'[Date]))
VAR __LastDateValue = CALCULATE(SUM('Equity Markets (2)'[Value]),
LASTDATE('Equity Markets (2)'[Date]))
RETURN
CALCULATE(
DIVIDE(__LastDateValue,__EarliestValue)-1)

CakePHP 3 - Comparing and modifying dates

In the CakePHP 3 Cookbook on Date/Time, you can compare time intervals with future/past days/weeks using IsWithinNext/WasWithinNext. You can also modify dates/times by doing a ->modify('extra time') - eg. if $date = 2016-01-01, $date->modify('+1 week') would mean $date = 2016-01-08.
These features require the use of Cake\i18n\Time. However, when I attempted to use these features, I received a Cake error:
Call to a member function isWithinNext() on string.
This is the code I used:
$date_start = \Cake\Database\Type::build('date')->marshal($data['session']['date_start'])->i18nFormat(); //before hand my dates were in the form of an array comprised of Year, Month and Day. This changes them into date format.
if($date_start->isWithinNext('1 week')){
$deposit_due = $booking->date_confirm;
$deposit_due->modify('+48 hours');
} elseif ($date_start->isWithinNext('2 weeks')){
$deposit_due = $booking->date_confirm;
$deposit_due->modify('+1 week');
} elseif ($date_start->isWithinNext('3 weeks')){
$deposit_due = $booking->date_confirm;
$deposit_due->modify('+1 week');
} else {
$deposit_due = $booking->date_confirm;
$deposit_due->modify('+2 weeks');
}
Calling i18nFormat() returns a formatted string as you can look up in the API: https://api.cakephp.org/3.4/class-Cake.I18n.DateFormatTrait.html#_i18nFormat
This, for example, should work:
$date_start = new \Cake\I18n\Time($data['session']['date_start']);
debug($date_start->isWithinNext('2 weeks'));

Crystal Reports -- How to show after decimal value differentnly in formula

I want to show after decimal 2 value in report but there a condition if value meet that condition then need to show full value. formula is given below but it is giving error
if trim({As400InTemp.PARTYCODE})='006883' then
{As400InTemp.SPPRIC}
else
round({As400InTemp.SPPRIC},2)
you can use MID like this:
"33.09789"
MID({yourstringhere}, 4)
or
MID(CSTR({yourstringhere}), 4)
it will return a value of 09789;

Trying to build Expression for Table field to sort text dates, some with missing elements

Hi I am a newbie and have a problem I have been trying to solve for weeks. I have a table imported from excel with dates in text format (because dates go back to 1700s) Most are in the format "mmmyyyy", so it is relatively easy to add "1" to the date, convert to date format, and sort in correct date order. The problem I have is that some of the dates in the table are simply "yyyy", and some are empty. I cannot find an expression that works to convert these last two to eg 1 Jan yyyy and 1 Jan 1000 within the same expression. Is this possible, or would I need to do this in two queries? Sorry if this question is very basic - I cannot find an answer anywhere.
TIA
You can do something like:
Public Function ConvertDate(Byval Expression As Variant) As Date
Dim Result As Date
If IsNull(Expression) Then
Result = DateSerial(1000, 1, 1)
ElseIf Len(Expression) = 4 Then
Result = DateSerial(Expression, 1, 1)
Else
Result = DateValue(Right(Expression, 4) & "/" & Left(Expression, 3) & "/1")
End If
ConvertDate = Result
End Function

SSRS Expression works as cell value expression, but not as background color value expression

I have an SSRS report with a matrix in it, where I needed to display the Growth Percentage in a column group compared to the previous column value. I managed this by using custom code...
DIM PreviousColValue AS Decimal
Dim RowName AS String = ""
Public Function GetPreviousColValue(byval Val as Decimal, byval rwName as string) as Decimal
DIM Local_PreviousColValue AS Decimal
IF RowName <> rwName THEN
RowName = rwName
PreviousColValue = val
Local_PreviousColValue = 0
ELSE
Local_PreviousColValue = (Val - PreviousColValue)/PreviousColValue
PreviousColValue = val
END IF
Return Local_PreviousColValue
End Function
..and then using this as the value expression in the cell..
=Round(Code.GetPreviousColValue(ReportItems!Textbox8.Value,Fields!BusinessUnit.Value)*100,0,system.MidpointRounding.AwayFromZero)
So far so good, this produces the expected value. Now I need to use this expression in a background color expression to get a red/yellow/green but in that capacity it fails.
The background color expression looks like this: =IIF(ROUND(Code.GetPreviousColValue(ReportItems!Textbox9.Value,Fields!Salesperson.Value)*100,0,System.MidpointRounding.AwayFromZero)<=-5,"Red"
,IIF(ROUND(Code.GetPreviousColValue(ReportItems!Textbox9.Value,Fields!Salesperson.Value)*100,0,System.MidpointRounding.AwayFromZero) >=5,"Green"
,"Yellow"))
When I run the report the background color expression only ever returns yellow. As a test I pasted the background color expression in as the cell value and ran it again. Results in the image below
I get no build or run time errors so I'm not sure why this does not work.
After some more searching I found a better Custom Code solution than what I was using to get the Growth Percentage in a column group compared to the previous column value. Besides being simpler to read this version has an added benefit: You can dynamically hide the growth percentage column for your first instance of the column group (because it will always be zero or null) and still get the right values in the 2nd/3rd/4th instance of the column group.
Public Function GetDeltaPercentage(ByVal PreviousValue, ByVal CurrentValue) As Object
If IsNothing(PreviousValue) OR IsNothing(CurrentValue) Then
Return Nothing
Else if PreviousValue = 0 OR CurrentValue = 0 Then
Return Nothing
Else
Return (CurrentValue - PreviousValue) / PreviousValue
End If
End Function
The new function is called like so
=Code.GetDeltaPercentage(Previous(Sum(<expression or dataset field>),"Group ByColumn"), Sum(<expression or dataset field>))
Re: the original question - why does my cell value expression not work when used as the background color expression - I took an easy out and just referenced the cell value.
=IIF(ROUND(Me.Value*100,0,System.MidpointRounding.AwayFromZero)<=-5,"Red"
,IIF(ROUND(Me.Value*100,0,System.MidpointRounding.AwayFromZero) >=5,"Green"
,"Yellow"))