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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
DMB90
Helper II
Helper II

How to Replace Blanks with Zero (0) in Switch Formula with Text

I have the following formula and I can't figure out how to make the blanks appear as zero "0".

 

Formula:

1.Q2 =

SWITCH(
    'Testing'[0.ACQuarters],
    "Q1 2025", "Q2 2025",
    "Q2 2025", "Q2 2025",
    BLANK())
1 ACCEPTED SOLUTION
cengizhanarslan
Super User
Super User

1.Q2 =
VAR Result =
    SWITCH (
        'Testing'[0.ACQuarters],
        "Q1 2025", "Q2 2025",
        "Q2 2025", "Q2 2025"
    )
RETURN
IF ( ISBLANK ( Result ), "0", Result )

 

Set Data type = Text

_________________________________________________________
If this helped, ✓ Mark as Solution | Kudos appreciated
Connect on LinkedIn | Follow on Medium
AI-assisted tools are used solely for wording support. All conclusions are independently reviewed.

View solution in original post

7 REPLIES 7
cengizhanarslan
Super User
Super User

1.Q2 =
VAR Result =
    SWITCH (
        'Testing'[0.ACQuarters],
        "Q1 2025", "Q2 2025",
        "Q2 2025", "Q2 2025"
    )
RETURN
IF ( ISBLANK ( Result ), "0", Result )

 

Set Data type = Text

_________________________________________________________
If this helped, ✓ Mark as Solution | Kudos appreciated
Connect on LinkedIn | Follow on Medium
AI-assisted tools are used solely for wording support. All conclusions are independently reviewed.

Thank you. This works.

 

Cookistador
Super User
Super User

Hi @DMB90 

 

The following dax measure should help you 

Q2 = 

COALESCE(

    SWITCH(

        'Testing'[0.ACQuarters],

        "Q1 2025", "Q2 2025",

        "Q2 2025", "Q2 2025"

    ), 

 

    0)

 

If you are using numerical field, replace the COALESCE() by a +0

I now received the message "Expressions that yield variant data-type cannot be used to define calculated columns"

 

What should the Data Type be?

this will be valid for a calculated column to keep everything as text. 

Q2 =
COALESCE(
SWITCH(
'Testing'[0.ACQuarters],
"Q1 2025", "Q2 2025",
"Q2 2025", "Q2 2025",
BLANK()
),
"0"
)



 

I now received the message "Expressions that yield variant data-type cannot be used to define calculated columns"

 

What should the Data Type be?

Sorry,  when I type the formula, I forgot the ""

 

Because you are working with textual value, and 0 is a numerical value, we have to convert it into string:

 

Q2 = 

COALESCE(

    SWITCH(

        'Testing'[0.ACQuarters],

        "Q1 2025", "Q2 2025",

        "Q2 2025", "Q2 2025"

    ), 

 

    "0")

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 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.