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

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.

Related

Trouble converting a text string to date in Notion

I'm trying to convert a text string into a date in Notion to build a birthday reminder system in my database.
Bigger picture, I want a database view with the birthdays that are coming up in the next month. Some people I know their actual date of birth, and for others I only know their birthday. I enter the birthdate for the people whose birth year I don't know as the current year.
The filters allow you to select a date relative to the present, but not a date whose anniversary is coming up. So to fix this, I am creating a field that reformats the birthdate as a date in the current year, and filtering based on that.
I successfully built the new date, but it is a text string. In order for the filters to work, it needs to be formatted as a date.
I tried formatDate but that gives me an error.
For example:
formatDate(concat(prop("Birthday"), ", ", prop("thisYear")), "MMMM D YYYY")
Gives error:
Type mismatch concat(prop("Birthday"), ", ", prop("thisYear")) is not a Date.
It appears formatDate only reformats an existing date, it doesn't convert a string into a date. I can't find a function that converts a string into a date. How would one do that?
to convert the date you have in text format into a prop date, you have to start from 01 Jan 1970, this is the date Notion use to refer every single date into ms.
With this formula you will have 01 Jan 1970 from now:
dateAdd(dateSubtract(dateSubtract(dateSubtract(dateSubtract(dateSubtract(now(),
year(now()) - 1970, "years"), month(now()), "months"), date(now()),
"days"), hour(now()), "hours"), minute(now()), "minutes"), 1, "days")
Now you have to add to this date months, year and days you have into your birthday prop.
To do this you simply have to use he dateAdd formula, so you will have:
dateAdd(dateAdd(dateAdd(dateSubtract(dateSubtract(dateSubtract(dateSubtract(dateSubtract(now(),
year(now()) - 1970, "years"), month(now()), "months"), date(now()),
"days"), hour(now()), "hours"), minute(now()), "minutes"),
prop("Giorni"), "days"), prop("Mese") - 1, "months"), prop("Anno") -
1970, "years")
You have to consider that in my example, prop("Giorni"), prop("Mese") and prop("Anno") are already numbers.
If you have them into a text field you first have to extract them with the slice formula and convert them into number with toNumber formula.
I hope I helped you, sorry for my English but I'm not native English speaker.
Bye

end of month/year data in tibco spotfire

I have the following dataset in tibco spotfire:
Original data
I want to bring the amount of item in the beginning of each month for each row and get the following result:
Image
Any suggestions?
The dataset looks like this: I have got maximum amount for previous month, but I want to get the amount of the last day of the previous month.
enter image description here
I could do it via an intermediate column (as Spotfire's OVER does not accept expressions).
First calculate the year and month like this:
(assuming the format of your date is known and stable)
[YearMonth] is :
Integer(Concatenate(Substring(String([Date]),7,4),Substring(String([Date]),4,2)))
then your [Previous Month] is:
Max([Amount]) over (Intersect(Previous([YearMonth]),[BRANCH],[CLASS]))
and your [Diff] is:
[Amount] - [Previous Month]
Revised after comment 19 August:
change the Max to ValueForMax and insert the day of the month, so that the formula calculates the value
corresponding to the last recorded day for that month:
ValueForMax(DayOfMonth([Date]),[Amount]) over (Intersect(Previous([YearMonth]),[BRANCH],[CLASS]))
Revised after comments 6 October:
if Substring(..) is not available, here is an alternative solution:
Create a new column (to make the expressions understandable): [StringMonth] as:
If(LongInteger(Month([Date]))>10,String(LongInteger(Month([Date]))), Concatenate('0',String(LongInteger(Month([Date])))))
Then calculate your [YearMonth] as:
Integer(Concatenate(Year([Date]),[StringMonth]))

Using Unix US Formatted Date-time-year for calculations in Excel

I have dates that are formatting using the default time formats for Bash (echo $date) for example:
Fri Dec 24 07:35:41 EST 2021
I cannot change this behavior as I don't have permissions to alter our IT solution. I need to be able to load these dates into a UK localised Excel, but any attempts to use the usual Text To Columns DMY approach doesnt work due to the Day, time zone, time etc.
Is the only way to extract the data and re-assemble it or is there a simpler solution?
Try this function . write it to module and call from any cell . Like =makeDateFromStr(A1)
Function makeDateFromStr(ByVal someDate As String) As Date
On Error Resume Next
Dim var As Variant, Mu As Long
var = Split(someDate, " ") ' array to hold all parts of the string-date
Mu = (InStr("JanFebMarAprMayJunJulAugSepOctNovDec", var(1)) + 2) / 3 ' a way to make short string month (Dec) to number
makeDateFromStr = DateSerial(var(5), Mu, var(2)) & " " & TimeValue(var(3)) ' putting all together
On Error GoTo 0
End Function
As far as I can see, if we get rid of the EST and the week day FRI, we can get a valid date value. Note: If you want the weekday, you can use the function WEEKDAY() to get the value 6, which is Friday. (1 is Sunday).
So, to get rid of the weekday, you can use the RIGHT() function.
All weekdays are 3 letters and a space, so we need to get rid of the 4 first characters, like so:
=RIGHT(A1;LEN(A1)-4)
You can put this just underneath your example time, so place this in cell A2.
To remove the EST is a bit more tricky, we need to know where in the text EST is. For this, we use FIND():
=FIND("EST ";A2)
Now we know at which position the text "EST " appears in A2.
Then we can use a simple REPLACE() function, to replace "EST " with nothing. Like so:
=REPLACE(A2;FIND("EST ";A2);4;"")
Note: The 4 refers to the length of "EST ".
This worked for this example, so you can try it out with different data. Just comment below if it isn't working correctly, and with what data and I'll look into it.
Put a date in A1
Put =RIGHT(A1;LEN(A1)-4) in A2
Put =REPLACE(A2;FIND("EST ";A2);4;"") in A3
You could also merge it into 1 cell:
=REPLACE(RIGHT(A1;LEN(A1)-4);FIND("EST ";RIGHT(A1;LEN(A1)-4));4;"")
You could then place this next to the date in A1, so in B1, and drag this formula down for ALL your imported dates. Now it should work for all of your dates.
You could also copy their values and replace the original dates, then remove the formulas, and you will have the same layout and functionality you were expecting from the beginning!

Excel Using concatenate to compare dates

I have a table containing several columns of which one is a date/time field. I am trying to get a count of instances per day using the following
=COUNTIFS(Table4[Data],"Apple",Table4[Date],(CONCATENATE(V4,"*")))
Data Date Comp Date Count
Apple 6/12/18 1:00 PM 6/12/18 12:00 AM 0
Apple 6/12/18 7:00 AM
Orange 6/12/18 1:30 PM
Apple 6/11/18 11:23 AM
From my understanding of all the moving parts here I should be checking to see if "Apple" exists in the data column and then if "6/12/18" with any amount or type of characters after it exists. If both are true I will then get a count + 1 leaving me with a value of 2 in the above example.
What I actually get however is a 0 unless I match the time portion of date the data to be exactly the same and then removed the wildcard ,"*" from the equation.
Am I doing something wrong or can the wildcard not be used to accomplish what I am trying?
Thanks!
I think you should set your criteria properly.
If you add an additional column next to your Date that contains calculates the integer value of your date using INT() and format the display as DATE (m/d/yyyy) you should then be able to use the following COUNTIFS formula
=COUNTIFS(Table4[Data], "Apple", Table4[Date], "=6/12/18")
See the explanatory video from their Office' support site: https://support.office.com/en-us/article/countifs-function-dda3dc6e-f74e-4aee-88bc-aa8c2a866842
If your [Date] column is a datetime or smalldatetime, you can work with it using CONVERT function, depending on how you want to group.
For example, if you don't care about the time to do the group, you could use the next query:
SELECT CONVERT(varchar,[Date],103), [Data], COUNT(*)
FROM [test_delete].[dbo].[Table1]
GROUP BY CONVERT(varchar,[Date],103), [Data]
This should result in something like this:
[Date] [Data] [Count]
11/06/2018 Apple 1
12/06/2018 Apple 2
12/06/2018 Orange 1
Hope this helps you
If your dates are stored as dates instead of text, use the following:
=COUNTIFS(Table4[Data],"Apple",Table4[Date],">="&V4,Table4[Date],"<"&V4+1)

CALM Query to get a specifc day and month from any year

I'd like to create a CALM query to get days and months of any year. Example:
In a list with the results below, I'd like to get all dates that have day equals 10 and month equals 07:
07/10/1984
01/02/2001
05/12/1991
07/10/2007
So, the result would be:
07/10/1984
07/10/2007
I don't think you will be able to do it directly in CAML for any year so you would end up listing out that day and month range for every year - bit of a monster.
Are you able to add extra calculated columns to your list? If so then you can add
DayAndMonth = Day([YourDate]) & "-" & Month([YourDate])
Then its a simple case of filtering using CAML or normal view filter (assuming US date format)
DayAndMonth = "7-10"

Resources