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
You can extract the date from the "Correction Notes" column in Power BI using DAX:
ExtractedDate =
VAR TextValue = 'Table'[Correction Notes]
-- Find the first occurrence of a date format
VAR Date1 = MID(TextValue, SEARCH("/", TextValue, 1, 0) - 2, 10) -- MM/DD/YYYY or MM/DD/YY
VAR Date2 = MID(TextValue, SEARCH("jan", LOWER(TextValue) & "jan", 1, 0) - 2, 9) -- DDMMMYYYY format
-- Return the first found date
RETURN IF(NOT(ISERROR(Date1)), Date1, Date2)