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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
DavidS-RI
Frequent Visitor

Conditional columns and null values

I am transforming data from Dataverse, and I have rows that look like this:

Field1Field2
ABCnull
nullDEF
GHInull

 

I want to create a new column to combine these two:

Field1Field2Field3
ABCnullABC
nullDEFDEF
GHInullGHI

 

The Conditional Column "wizard" doesn't have a "contains data" or "does not contain data" option available, so I try using the equals condition with a blank value. The resulting formula for my column becomes:

=Table.AddColumn(#"PreviousStepName", "Field3," each if [Field1] <> "" then [Field1] else [Field2])

 

That seems simple enough but in practice I get unexpected results, with different .pbix files generating different outcomes. Sometimes the above formula works, but sometimes the result for Field3 is null and sometimes it's Error. I've had some luck replacing if [Field1] <> "" with if Text.Length([Field1]) >0, but that doesn't always seem to work either.

 

What is the best way to say "set Field 3 to the value of Field 1, unless Field 1 has a null value, in which case use the value of Field 2?"

 

In case it matters, the fields in question are not coming from the same table in the Dataverse. My queries start with one table that's related to two other tables. In previous steps within my query, I expand those two related tables, selecting Field1 from RelatedTable1 and Field2 from RelatedTable2. Sometimes I maintain the source table name as a prefix when I expand it, sometimes I don't. Could that inconsistency explain why my conditional column formula produces inconsistent results? 

6 REPLIES 6
AlienSx
Super User
Super User

@DavidS-RI 

Table.AddColumn(#"PreviousStepName", "Field3", each [Field1] ?? "" & [Field2] ?? "")
Anonymous
Not applicable

Hi @DavidS-RI 

You can use List.Max() function, you can create a custom column.

List.Max({[Field1],[Field2]})

 Output

vxinruzhumsft_0-1704091028476.png

 

Best Regards!

Yolo Zhu

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

This did not work for me. The value of the custom column was Error for all rows.

DavidS-RI
Frequent Visitor

Your first option does not work. "null" in quotation marks seems to look for the actual word null as a text value, but null without quotation marks seems to check for the absence of any data, as intended. So your second option seems to work, at least in my first test of this. I wonder why the GUI inserts "" into the formula rather than null. 

Hi @DavidS-RI 

I have inserted "" in the last, please change it if required.


If solved your requirement, please mark this answer as SOLUTION.
If this comment helps you, appreciate your KUDOS




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





PijushRoy
Super User
Super User

Hi @DavidS-RI 

Please try this in custom column in PQ

if [Field1]="null" and [Field2]<>"null" then [Field2] else if [Field1]<>"null" and [Field2]="null" then [Field1] else ""

or 

if [Field1]=null and [Field2]<>null then [Field2] else if [Field1]<>null and [Field2]=null then [Field1] else ""

 

PijushRoy_0-1703879724487.png

If solved your requirement, please mark this answer as SOLUTION.
If this comment helps you, appreciate your KUDOS

Pijush

 




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.