cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
akhaliq7
Continued Contributor
Continued Contributor

Date column contains text and would like to turn it to null

I have a date column that contains date values but some rows also contain text values. I want to replace all text values to null. Using Power Query and the M language ideally.

 

I have thought of some solutions but the code is returning errors

 

Solution 1:

 

= Table.SelectRows(Table, each if Text.Length([Column1]) > 0 then null else [Column1])

 

this is returning a error message:

Expression.Error: We cannot convert the value #date(2022, 1, 20) to type Text.
Details:
Value=20/01/2022
Type=[Type]

1 ACCEPTED SOLUTION
slorin
Super User
Super User

Hi

Change type to date then replace error with null

= Table.ReplaceErrorValues(Table.TransformColumnTypes(PrevStep,{{"Column1", type date}}), {{"Column1", null}})

Or replace text with null

= Table.ReplaceValue(PrevStep,each Type.Is(Value.Type([Column1]),type text),null,(x,y,z)=>if y then z else x,{"Column1"}) 

Stéphane 

View solution in original post

4 REPLIES 4
slorin
Super User
Super User

Yes, you're right

x = record (the entire row) 

if "x[Column1].type = text" then null else x[Column1]

 

Stéphane

akhaliq7
Continued Contributor
Continued Contributor

thanks

slorin
Super User
Super User

Hi

Change type to date then replace error with null

= Table.ReplaceErrorValues(Table.TransformColumnTypes(PrevStep,{{"Column1", type date}}), {{"Column1", null}})

Or replace text with null

= Table.ReplaceValue(PrevStep,each Type.Is(Value.Type([Column1]),type text),null,(x,y,z)=>if y then z else x,{"Column1"}) 

Stéphane 

akhaliq7
Continued Contributor
Continued Contributor

Can you explain the (x,y,z) => if y then z else x

i get y is the logic type.is

z is null 

but not sure what x is i am guessing that is the value that exists already in that column beforehand

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors