The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event: Join us in Stockholm, September 24-27, 2024.
Save €200 with code MSCUST on top of early bird pricing!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
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]
Solved! Go to Solution.
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
Yes, you're right
x = record (the entire row)
if "x[Column1].type = text" then null else x[Column1]
Stéphane
thanks
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
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
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the August 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
180 | |
52 | |
39 | |
27 | |
25 |