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 want to create new column by using custom column function in Power Query Editor.
New_Column = [Column A] & "-" & [Column B]
ex. [Comlumn A] is null and the [Column B] is "Good", the result was null.
[Comlumn A] is null and the [Column B] is null, the result was null.
[Comlumn A] is "Good" and the [Column B] is null, the result was null.
Please help me to figure it out,
Thank you 😻
Solved! Go to Solution.
@ImkeF's solution is great if you don't want a hyphen when one column is null.
If you want the hyphen (as in your specified example), then the coalesce operator is handy if you don't want to replace nulls with empty strings as a separate step or write out the equivalent if statements.
([Column A] ?? "") & "-" & ([Column B] ?? "")
Hi @Anonymous ,
Did the answers above help you? If so, please consider marking the most helpful answer as a solution, as this will help people searching the forum for similar questions in the future to find answers more quickly. Thanks in advance!
If the question remains unresolved, you can continue to add details to the question below and feel free to contact us.
Best Regards,
Gao
Community Support Team
@ImkeF's solution is great if you don't want a hyphen when one column is null.
If you want the hyphen (as in your specified example), then the coalesce operator is handy if you don't want to replace nulls with empty strings as a separate step or write out the equivalent if statements.
([Column A] ?? "") & "-" & ([Column B] ?? "")
Thank you for this solution! 😍
In general, null <operator> value => null
@ImkeF solution is an excellent one. You could also use an If statement to convert the null to "".
Hi @Anonymous ,
try using this instead:
Text.Combine( { [Column A], [Column B] }, "-" )
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Thank you so much!
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.