Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
SophRow
Resolver II
Resolver II

Converting UNK to 01 in Power Query

Hi

 

I'm importing date data into Power BI that in some cases uses "UNK" when either the day or month are unknown. This causes an error message:

 

DataFormat.Error: We couldn't parse the input provided as a Date value.
Details:
UNK-JAN-2021

 

I have converted the colum to text and am trying to replace "UNK" with "01" so I can convert back to date and it will be solved - but it's not working.

 

Any ideas?

 

Best,

Soph

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

Issue this statement where Source needs to be replaced with your previous step and Data with your column name

Table.ReplaceValue(Source,each [Data],each Text.Replace([Data],"UNK","01"),Replacer.ReplaceValue,{"Data"})

  See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCvXz1vVy9NM1MjAyVIrVgQg4BgShCri4OkMFYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t]),
    Custom1 = Table.ReplaceValue(Source,each [Data],each Text.Replace([Data],"UNK","01"),Replacer.ReplaceValue,{"Data"}),
    #"Changed Type" = Table.TransformColumnTypes(Custom1,{{"Data", type date}})
in
    #"Changed Type"

View solution in original post

2 REPLIES 2
SophRow
Resolver II
Resolver II

Wonderful @Vijay_A_Verma thank you!

Vijay_A_Verma
Super User
Super User

Issue this statement where Source needs to be replaced with your previous step and Data with your column name

Table.ReplaceValue(Source,each [Data],each Text.Replace([Data],"UNK","01"),Replacer.ReplaceValue,{"Data"})

  See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCvXz1vVy9NM1MjAyVIrVgQg4BgShCri4OkMFYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t]),
    Custom1 = Table.ReplaceValue(Source,each [Data],each Text.Replace([Data],"UNK","01"),Replacer.ReplaceValue,{"Data"}),
    #"Changed Type" = Table.TransformColumnTypes(Custom1,{{"Data", type date}})
in
    #"Changed Type"

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors