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
rafaelsmoreno
Frequent Visitor

Replace NULL by data in other column - powequery, M

Hello everyone,

 

I have the following problem: In a timesheet database I have two columns with department name. One is the Department of Origin, e.g. IT. The other is the Charged Dept., e.g. Finance.

What happens is that the entry of a person who performed a task to its own department comes with a null value at charged department column, so I would like to apply a text replacement on it, in a way that if the charged department is null it would be replaced by the origin department.  

I can solve the problem by creating a new column and using If statements, but I would like to know if it is possible to apply Table.ReplaceValue (or something like that) to change the null entry to the value of the entry of the other column. 

I tried the following code, without success:

 

#"Replaced Value" = Table.ReplaceValue(#"PreviousStep",null, each [OriginDept],Replacer.ReplaceValue,{"ChargedDept"})

 

Thank you, guys, in advance!

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

There's probably a way to do that the way you are referring to but you could always do this:

 

    #"Added Conditional Column" = Table.AddColumn(#"Removed Duplicates", "Custom", each if [CcRecipients.Address] = null then [ToRecipients.Address] else [CcRecipients.Address])

Or, this:

 

    #"Replaced Value" = Table.ReplaceValue(#"Added Conditional Column",null,each [ToRecipients.Address],Replacer.ReplaceValue,{"CcRecipients.Address"})

That last one looks like what you were  going for, that worked for me as well.


@ 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...

View solution in original post

1 REPLY 1
Greg_Deckler
Super User
Super User

There's probably a way to do that the way you are referring to but you could always do this:

 

    #"Added Conditional Column" = Table.AddColumn(#"Removed Duplicates", "Custom", each if [CcRecipients.Address] = null then [ToRecipients.Address] else [CcRecipients.Address])

Or, this:

 

    #"Replaced Value" = Table.ReplaceValue(#"Added Conditional Column",null,each [ToRecipients.Address],Replacer.ReplaceValue,{"CcRecipients.Address"})

That last one looks like what you were  going for, that worked for me as well.


@ 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