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
sammyboi
New Member

Creating a conditional column with null value

Hi there!


I am trying to create a conditional column to return values based on the following logic:

 

if column a is null, then column a should equal to column b

if column a and column b are both null, then column a should equal column c

all else should equal to column a

 

Could you please advise how I should phrase this using the Conditonal Column function?

7 REPLIES 7
MahyarTF
Memorable Member
Memorable Member

Hi,

In addition to the @grantsamborn Post, you could create the below column and use it in your visual :

ResultCol =
            SWITCH(Sheet186[Column],
                   BLANK(), SWITCH(Sheet186[A],
                                   BLANK(), SWITCH(Sheet186[B],
                                                   BLANK(), Sheet186[C], Sheet186[B]),
                                   Sheet186[A]),
                  Sheet186[Column])
Appreciate your Kudos
Mahyartf

A couple questions/comments:

1 - When creating a calculated column, the table name isn't necessary.
2 - I'm not sure where you came up with Sheet186[Column].
3 - While I realize SWITCH has its places, please explain how in a simple case like this it easier to read than using IF.

 

grantsamborn =
IF(
    ISBLANK( [ColumnA] ),
    IF(
        ISBLANK( [ColumnB] ),
        [ColumnC],
        [ColumnB]
    ),
    [ColumnA]
)


MahyarTF =
SWITCH(
    Sheet186[Column],
    BLANK(),
        SWITCH(
            Sheet186[A],
            BLANK(),
                SWITCH(
                    Sheet186[B],
                    BLANK(), Sheet186[C],
                    Sheet186[B]
                ),
            Sheet186[A]
        ),
    Sheet186[Column]
)

Hi,

1- Yes, You are right, for the calc column not need to bring the table name (as in the sample file, I have a multi same columns, I wrote the table name and just copy the code)

2- my Table structure is like below (I bring one more column ) :

MahyarTF_0-1662953132433.png

3- As you know there is more than one solution. I mentioned that your answer I good, but sometimes the codes' performance should be considered.

As you see in below image I run the codes for comparing the performance and it should be not same (should check in real data by user to find the best solution :

MahyarTF_1-1662953387690.png

 

Thanks for letting me know

Mahyartf

Correct me if I am wrong, but I believe calculated columns are only calculated on refresh of the dataset - NOT on the refresh of visuals.

That is correct. Or also upon editing the calculated column.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

This is the first I've heard of a sample file.

Good luck.

 

grantsamborn
Solution Sage
Solution Sage

Based on your description:
if column a is null, then column a should equal to column b
if column a and column b are both null, then column a should equal column c
all else should equal to column a

 

I'm guessing that you mean something like this. If not, I don't understand.
if column a is null, then RESULT should equal column b
if column a and column b are both null, then RESULT should equal column c
else RESULT should equal to column a

 

If I do understand, is this what you are looking for?

 

z=
IF(
	ISBLANK( [ColumnA] ),
	IF(
		ISBLANK( [ColumnB] ),
		[ColumnC],
		[ColumnB]
	),
	[ColumnA]
)

 

 

(If the difference is between NULLs and BLANKs, maybe PowerQuery would be the place to make the substitution.)

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.