Forum Discussion
Need help on one logic
- 1 year ago
Hi ajitsahoo8338 Try this in custom column:
Simple version (Just Extract The First Date Before Delimeter space, colon etc and then fix the date type):
List.First( List.Transform( Text.SplitAny([Correction Notes], ": "), each Text.Trim(_) ) )Output:
Complete version :
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], #"Changed Type" = Table.TransformColumnTypes(Source,{{"Project Name", type text}, {"Correction Notes", type text}}), // Extract the first date segment before any delimiter (-, :, space) #"Added ExtractedDateText" = Table.AddColumn(#"Changed Type", "ExtractedDateText", each Text.Trim( Text.Start( [Correction Notes], let text = [Correction Notes], delimiters = {"-", ":", " "}, positions = List.Transform(delimiters, each Text.PositionOf(text, _, Occurrence.First)), validPositions = List.Select(positions, each _ >= 0), minPosition = if List.IsEmpty(validPositions) then Text.Length(text) else List.Min(validPositions) in minPosition ) ) ), // Parse the extracted date text using multiple formats #"Added ParsedDate" = Table.AddColumn(#"Added ExtractedDateText", "ParsedDate", each let dateText = [ExtractedDateText], tryFormat1 = try DateTime.FromText(dateText, [Format="M/d/yyyy", Culture="en-US"]), tryFormat2 = try DateTime.FromText(dateText, [Format="M/d/yy", Culture="en-US"]), tryFormat3 = try DateTime.FromText(dateText, [Format="ddMMMyyyy", Culture="en-US"]), result = if not tryFormat1[HasError] then tryFormat1[Value] else if not tryFormat2[HasError] then tryFormat2[Value] else if not tryFormat3[HasError] then tryFormat3[Value] else null in result ), // Ensure the ParsedDate column is of type date #"Changed Type1" = Table.TransformColumnTypes(#"Added ParsedDate",{{"ParsedDate", type date}}) in #"Changed Type1"Output:
Hope this helps!!
If this solved your problem, please accept it as a solution and a kudos!!
Best Regards,
Shahariar Hafiz
ajitsahoo8338 , assuming the correction notes is a column of your table. You'll need to
1) split text by de delimiter(by space/-/:). It seems like you need to do multiple step to clean it properly
2) Change splitted text into date format. While it can be change from DDMMYYYY or MMDDYYYY, there needs to be a consistency on what it should be changed from or you could identify a logic to determine if its meant to be ddmmyyyy or mmddyyyy.
Should there be no possible logic, you could try and catch error -> if they don't fall in DDMMYYYY convert as MMDDYYYY. Hope this helps