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
benjamin_sasin
Resolver I
Resolver I

Replacing Blanks in Power Query inside a Table.ReplaceValue() function

I am trying to figure out how to replace blanks in Power Query, but all Google an Forum search lead me to using DAX, which is not what I am looking for, as I want to use Power M query. Also, searching for "blank" in the Power M Query documentation leads to nothing relevant.

 

I tried replacing "" with text, assuming "" is blank, but that somehow replaces the majority of rows and yet still leaves a couple of rows as "(blank)".

 

I'm using a Table.ReplaceValue() function. How can I replace blanks within that? 

 

Thanks

3 ACCEPTED SOLUTIONS
dax
Community Support
Community Support

Hi @benjamin_sasin , 

You said that some rows didn't replace blank, right? I think this might be cause by space, some rows are " " instead of "", so when you use "", it doesn't work. You could try below M code to see the difference and see whetehr it work or not

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTJUitWJVkoGssAMBSDDGMwCMvJKc3Lg0qZKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [name = _t, Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"name", type text}, {"Column1", Int64.Type}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "name", "name - Copy"),
    #"Replaced Value1" = Table.ReplaceValue(#"Duplicated Column","","replace",Replacer.ReplaceValue,{"name - Copy"}),
    #"Replaced Value" = Table.ReplaceValue(#"Replaced Value1",each [name],each if Text.Trim([name])="" then "replace blank" else [name],Replacer.ReplaceValue,{"name"})
in
    #"Replaced Value"

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

benjamin_sasin
Resolver I
Resolver I

Thanks everyone.

 

So it turns out the problem wasn't Power Query, but on Power Bi.

 

My Table B with blanks was connected with another Table A, where Table A Left Join Table B. As a result, some rows in A didn't have a matching row in B and so the output was "blank", so I had to created a calculated column on Power BI to correct the gap.

View solution in original post

Hi @benjamin_sasin , 

When create relationship, records don't match will cause blank row, you could try to create measure or column, then apply this in filter and set "is not blank" to see whether it work or not. Or try to set many-to many to see whether it work or not.

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

8 REPLIES 8
durlav1993
Frequent Visitor

i have to separate excel sheet 1. headcount(Col-DOJ) 2. attrition (col-LWD)

so , i have to find out the current emp count abstract from the attrition emp.

i used following DAX :

_noofHeadsCurr =
CALCULATE(
DISTINCTCOUNT(headcount[Employee ID]),
CROSSFILTER('calendar'[date], headcount[DOJ], None),
headcount[LWD] = BLANK()
) +0

 

 

vasoochigava
Frequent Visitor

Easiest Solution: using no dax and no M code. In power query just press replace values. leave value to find as blank, value to replace with something you want to replace, then in advanced options tick match entire cells contents. Woalah!

benjamin_sasin
Resolver I
Resolver I

Thanks everyone.

 

So it turns out the problem wasn't Power Query, but on Power Bi.

 

My Table B with blanks was connected with another Table A, where Table A Left Join Table B. As a result, some rows in A didn't have a matching row in B and so the output was "blank", so I had to created a calculated column on Power BI to correct the gap.

Hi @benjamin_sasin , 

When create relationship, records don't match will cause blank row, you could try to create measure or column, then apply this in filter and set "is not blank" to see whether it work or not. Or try to set many-to many to see whether it work or not.

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

dax
Community Support
Community Support

Hi @benjamin_sasin , 

You said that some rows didn't replace blank, right? I think this might be cause by space, some rows are " " instead of "", so when you use "", it doesn't work. You could try below M code to see the difference and see whetehr it work or not

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTJUitWJVkoGssAMBSDDGMwCMvJKc3Lg0qZKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [name = _t, Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"name", type text}, {"Column1", Int64.Type}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "name", "name - Copy"),
    #"Replaced Value1" = Table.ReplaceValue(#"Duplicated Column","","replace",Replacer.ReplaceValue,{"name - Copy"}),
    #"Replaced Value" = Table.ReplaceValue(#"Replaced Value1",each [name],each if Text.Trim([name])="" then "replace blank" else [name],Replacer.ReplaceValue,{"name"})
in
    #"Replaced Value"

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

You really served my day 🤗 🤝.

 

Anonymous
Not applicable

Hi @benjamin_sasin ,

 

did you try something like this?

Table.ReplaceValue(#"Added Custom","(blank)",null,Replacer.ReplaceValue,{"File Date", "Expiry Date", "2011"})

I.e. searching for "(blank)" rather then ""...

 

Kind regards,

JB  

Greg_Deckler
Super User
Super User

Try using null instead of ""

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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