Datediff with null in Spotfire - spotfire

I'm trying to calculate the difference between two dates, but if the "end date" has a null, like in rows two and four, then I'd like to put in "today"....the data table looks like such.
Hire Date Term Date = "end date"
01/01/2019 05/01/2020
05/04/2018
09/17/2019 03/18/2020
10/19/2018
I was think something like this would work but it's not...
If([Term Date]<>NULL THEN DateDiff("year",[Hire Date],[Term Date])
ELSE DateDiff("year",[Hire Date],Today())
END
Thanks in advance!

You can use a SN() which is substitute Null.
DateDiff('year',[Hire Date] , SN([TermDate],Today() ) )
or use a case statement instead of a IF as your format for an IF statement is incorrect -
If(argument, True, False) is the proper format but a case is easier to work with at some points .
Case when [Term Date] is null then DateDiff("year",[Hire Date],Today())
else DateDiff("year",[Hire Date],[Term Date])
end

Related

Create Date from MM/DD format and include current year? Power Query

I have a table that has a series of Columns with data I need to split out. Example below
STATUS#10/16 12:00:00 (CODE)
I've been able to split it easy enough and when I originally tried to set the date on an older dataset it identified it as a date e.g. 16th Oct 2021 However I started to get errors on this date column and trying with different datasets (10/12, 10/13, 10/14) it is not finding the date. I tried the following query code but I'm receiving errors
[STATUS DATE] is split to 10/14, 10/15 etc
#date( Date.Year(DateTime.LocalNow), Date.Month(Text.End([STATUS DATE]), 2), Date.Day(Text.Start([STATUS DATE]),2))
However I'm getting a function error so I tried
Date.From(Date.Day(Text.Start([STATUS DATE]),2) & Date.Month(Text.End([STATUS DATE]),2) & Date.Year(DateTime.LocalNow)
I have also tried to do this from an example column however the query created is looking at the cell value e.g. if 10/14 then 14/10/2021 else if 13/10 then 14/10/2021. This method i feel is prone for error once I include a larger dataset.
Is there anyway I can determine the date value based on mm/dd format? But with year end in mind, make the YYYY be determined by current year unless we move into Jan and then I don't want the Oct, Nov, Dec value showing as 2022.
You don't really show what your original data looks like.
But if it is like:
Source
Then you can use this code in the Add Custom Column dialog:
let
split=Text.SplitAny([STATUS DATE],"#/ "),
mnth = Number.From(split{1}),
dy = Number.From(split{2})
in
#date(Date.Year(DateTime.LocalNow()),mnth,dy)
The Text.SplitAny function lets you input a list of delimiters and the text will split on all of them. So it is relatively simple to extract the month and day values
to create:
Split [STATUS DATE] one more time into [Month] and [Day] column, using the "/" as a separator. Then you don't have to bother with 1 or 2 digit numbers and you can simply use this formula:
#date(Date.Year(DateTime.LocalNow()), [Month], [Day])
DateTime.LocalNow() is a function, so you need to add the brackets.
[Month] and [Day] are numbers already, so you don't need the Date.Month() or Date.Day() functions.

SSRS concatenating parameters values to obtain date in the end

hi guys i have the expression below which i am trying to use to concatenate some int param values and one int value.
In the end i want a date for the last day of the month based on what the user selected.
Spent all day on this, couldn't find anything in stack.
=Parameters!Year.Value & 10 & IIF(LEN(Parameters!Period.Value) <= 1,0 &
Parameters!Period.Value,Parameters!Period.Value)
Supposing that "Period" is the month, you are most likely looking for something like this:
=DateSerial(Parameters!Year.Value, Parameters!Period.Value, 1).AddMonths(1).AddDays(-1)

saved search to pull date invoice was paid in full

I've a transaction saved search in which I've various formula columns displaying invoice date, any related credits, and then actual payments after any term discounts taken. Now I need to add another column to display the date invoice was marked "Paid in Full" I'm using the formula which is not working: case when {systemnotes.newvalue} = 'paid in full' then {systemnotes.date} end
I can't use 'date closed' because that's just displays the most recent payment date against an invoice and not the date it was fully applied for example an old credit memo.
Any input is appreciated.
Oracle string comparisons are case sensitive. {systemnotes.newvalue} returns 'Paid In Full' - not 'paid in full' (note the Title Case). You can correct the comparison to use Title Case like this:
case when {systemnotes.newvalue} = 'Paid In Full' then {systemnotes.date} end
or you can coerce both sides to upper or lower case for a slightly more robust comparison:
case when UPPER({systemnotes.newvalue}) = UPPER('paid in full') then {systemnotes.date} end
I've tested both of these and they work for me.
Why not just use the Date Closed? (closedate)

Date status function to displays Overdue, Due Later and Due Soon

I am currently working on function in Excel that will display the status of an activity based on the due date provided.
This function would display:
"Overdue" if Today()> Due Date;
"Due Soon" If the Due date was within one week
"Due Later" if Today() < Due Date +7
Below is an example of what I was able to muster up:
Function Status_of_Date()
If Sheets("Issue_Log").Range("Due_Date").Value < Date Then
Sheets("Issue_Log").Range("Date_Status").Value = "Overdue" 'overdue
ElseIf Sheets("Issue_Log").Range("Due_Date").Value < 7 + Date Then
Sheets("Issue_Log").Range("Date_Status").Value = "Due Later" ' Due Soon
ElseIf Sheets("Issue_Log").Range("Due_Date").Value > 7 + Date Then
Sheets("Issue_Log").Range("Date_Status").Value = "Due Later" ' Due Later
Else
End If
End Function
Codeless Solution
Add a column to your table, to count the days left - since anything negative is overdue anyway, make all negatives -1:
Use a table formula to calculate it:
=IF([#[Due Date]]-TODAY()<0,-1,[#[Due Date]]-TODAY())
Next, have another table to hold the status given a number of days:
Since you have 3 statuses, and they're really ranges of values, to achieve the values you're after you'll need:
A row with -1 for everything Overdue
A row with 0 for everything due Soon
A row with 7 for everything due Later
Now your "Date Status" column can be a simple VLOOKUP formula:
Again, a table formula is used; note the "approximate match" last parameter:
=VLOOKUP([#Days],tblStatusLookup,2,TRUE)
Adjust tblStatusLookup to whatever you've named your lookup table.
Look 'ma, not a single line of code!
Then you can hide the [Days] column if you don't need it shown, and the lookup table can be anywhere you want - and if the thresholds need to change, or if new statuses need to be added, you just tweak the lookup table (important: keep the [Days] sorted ascending, that's how approximate match VLOOKUP works!)
Bugs in OP
Your function needs to know what row to work with. That should be a parameter; change the signature to accept one - or even better, change it to accept a DueDate parameter - then you simply don't need to care about anything other than the date you're given:
Public Function GetDateStatus(ByVal dueDate As Date) As String
If dueDate - Date < 0 Then
GetDateStatus = "Overdue"
ElseIf dueDate - Date < 7 Then
GetDateStatus = "Due Soon"
Else
GetDateStatus = "Due Later"
End If
End function
And then in your table the formula would be:
=GetDateStatus(#[Due Date])
No need to be bothered with ranges and the nitty-gritty details of how and where every value is coming from - code gets much, much simpler when you work at the right abstraction level!
Note that a worksheet function is not allowed to change other cells' values: it calculates a value.

Subtracting from a date in VBA?

I'm having big problems doing operation with the date in Excel VBA.
I have a form that has a textbox where the user will enter the date. The problem is that he may enter it in different formats (eg, 1.08.2011 for 1st of August, or 8/1/11 for the same day). Now what I want to do is to subtract some days from that date that he enters in the TextBox. I had to success so far and I don't know how to do it.
I tried something like this
Format((Format(Me.datalivrare.Value, "dd.mm.yyy") - 4), "dd.mm.yyyy")
Where datalivrare is that textbox where the user enters the date and 4 is the number of days I want to subtract from that date... and I want the format to always be dd.mm.yyyy no matter what they enter in that textbox.
I suggest looking at the DateAdd function for VBA
http://www.techonthenet.com/excel/formulas/dateadd.php
http://office.microsoft.com/en-us/access-help/dateadd-function-HA001228810.aspx
You could do the following:
Format(DateAdd("d", -4, CDate(Me.datalivrare.Value)), "dd.mm.yyyy")
First cast to Date, then subtract days, then format appropriately:
Format(DateAdd("d", -4, CDate(Me.datalivrare.Value)), "dd.mm.yyyy")
the best to add and substract from dates on vba is dateadd() (with negative number for substractions)
also, in your example code there's a missing y on the format string (it accepts 1, 2 or 4 y, only)
It is important to check if the user entered a value that VBA can interprit as a date so first you should:
If isDate(Me.datalivrare.Value) Then
str_Date = Format(DateAdd("d", -4, CDate(Me.datalivrare.Value)), "dd.mm.yyyy")
Else
MsgBox "Not a valid date value", vbCritical + vbOkOnly, "Invalid Entry"
End If
I think bluefeet's answer had the most information so far and I borrowed the use of DateAdd and CDate.
Just a simple answer, as many aren't using the OP's code.
Eg: Minus 4 days
https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/dateadd-function
Sub DateTest()
Dim DateVar As Date
DateVar = DateAdd("d", -4, Date)
Debug.Print DateVar
End Sub

Resources