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
Rich_Wyeth
Helper I
Helper I

Handle Null in IF Statement

Hi,

 

I have the following column witha multiple if:

 

= Table.AddColumn(#"Due Days", "Due Category", each if [Due Days] >= 0 then "Overdue" else if [Due Days] <= -365 then "Over 12 Months" else if [Due Days] < -180 then "6-12 Months" else if [Due Days] < -90 then "3-6 Months" else if [Due Days] < -30 then "1-3 Months" else "1 Month")

 

I need to incase an statement that says if [Due Days] = null then Due Category will read null, as at present it is returning error. I have tried to do this, but I can't seem to get it right.

 

How to do create the check whilst adding the column?

 

Thanks in Advance

2 ACCEPTED SOLUTIONS
Angith_Nair
Continued Contributor
Continued Contributor

Hi @Rich_Wyeth 

 

Use the below M Code:

= Table.AddColumn(#"Due Days", "Due Category", each 
    if [Due Days] = null then null 
    else if [Due Days] >= 0 then "Overdue" 
    else if [Due Days] <= -365 then "Over 12 Months" 
    else if [Due Days] < -180 then "6-12 Months" 
    else if [Due Days] < -90 then "3-6 Months" 
    else if [Due Days] < -30 then "1-3 Months" 
    else "1 Month"
)

View solution in original post

FreemanZ
Super User
Super User

hi @Rich_Wyeth ,

 

try like:

= Table.AddColumn(

    #"Due Days", 

    "Due Category", 

   each 

    if [Due Days] >= 0 then "Overdue" 

    else if [Due Days] <= -365 then "Over 12 Months" 

    else if [Due Days] < -180 then "6-12 Months" 

    else if [Due Days] < -90 then "3-6 Months" 

    else if [Due Days] < -30 then "1-3 Months" 

    else if [Due Days] =null then null

    else "1 Month"

)

View solution in original post

3 REPLIES 3
FreemanZ
Super User
Super User

hi @Rich_Wyeth ,

 

try like:

= Table.AddColumn(

    #"Due Days", 

    "Due Category", 

   each 

    if [Due Days] >= 0 then "Overdue" 

    else if [Due Days] <= -365 then "Over 12 Months" 

    else if [Due Days] < -180 then "6-12 Months" 

    else if [Due Days] < -90 then "3-6 Months" 

    else if [Due Days] < -30 then "1-3 Months" 

    else if [Due Days] =null then null

    else "1 Month"

)

Angith_Nair
Continued Contributor
Continued Contributor

Hi @Rich_Wyeth 

 

Use the below M Code:

= Table.AddColumn(#"Due Days", "Due Category", each 
    if [Due Days] = null then null 
    else if [Due Days] >= 0 then "Overdue" 
    else if [Due Days] <= -365 then "Over 12 Months" 
    else if [Due Days] < -180 then "6-12 Months" 
    else if [Due Days] < -90 then "3-6 Months" 
    else if [Due Days] < -30 then "1-3 Months" 
    else "1 Month"
)

Thank you, works a treat! I was so transfixed on an if, I hadn't thought of that! Thank you!

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.