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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
kannanAhammed
Helper IV
Helper IV

Custom column to combine two Colum returns null if either of the Colum contain null value

Hi,

 

I created a custom column to concatinate two fields from transformation -> Add column -> custom column

The formula is  custom = [A] & [B]. If either if the colums value is null the result is null.

The null should be allowed only if both are null. how do i do this ?

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

Hi, @kannanAhammed , Null Coalescing Operator (??) does the trick

 

Table.AddColumn(#"Replaced Value", "Custom", each ([A]??"") & ([B]??"") & ([C]??""))

 

Screenshot 2021-01-04 110351.png

 

Just for fun, let's say, if you want to combine all columns (more than 10 columns) in a row, you might use the following code,

 

Table.AddColumn(#"Replaced Value", "Custom", each List.Accumulate(Record.ToList(_), "", (s,c)=>s&(c??"")))

 

Screenshot 2021-01-04 111230.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

4 REPLIES 4
v-cazheng-msft
Community Support
Community Support

Hi @kannanAhammed ,

You can directly use the expression custom=[A]&[B] to create a Calculated column, and you can get a column concatenating these two fields. If both of the fields are null, the result will be null.

 

The result looks like this:

v-cazheng-msft_0-1609897513265.png

 

 

Best Regards,

Caiyun Zheng

 

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

PhilipTreacy
Super User
Super User

Hi @kannanAhammed 

Your question isn't clear because you say 

  • If either if the colums value is null the result is null.
  • The null should be allowed only if both are null.

The first one means the result is null if either A or B is null.

The second one means the result is null only if A and B are null.

You can't have both.  If it's null only when A and B are null then the first condition is invalid.  Which is it?

I imagine the other answers will give you a solution but just needed to point out the question isn't logically clear.

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


CNENFRNL
Community Champion
Community Champion

Hi, @kannanAhammed , Null Coalescing Operator (??) does the trick

 

Table.AddColumn(#"Replaced Value", "Custom", each ([A]??"") & ([B]??"") & ([C]??""))

 

Screenshot 2021-01-04 110351.png

 

Just for fun, let's say, if you want to combine all columns (more than 10 columns) in a row, you might use the following code,

 

Table.AddColumn(#"Replaced Value", "Custom", each List.Accumulate(Record.ToList(_), "", (s,c)=>s&(c??"")))

 

Screenshot 2021-01-04 111230.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

amitchandak
Super User
Super User

@kannanAhammed , Try like

 

if [A] <> null && [B] <> null then [A] & [B] else if [A] <> null then [A] else [B]

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.