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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Anonymous
Not applicable

Need a semi complex if / Else statement

I'm trying to create a new column that looks at an existing column called % Completed (if contains numerical values from 0 to 1 and blanks) and then outputs text based off what value is in that column.  I've tried a bunch of formats.  No luck.  Here is the gist...

 

If % Completed = 1, "100% Completed"

elseif % Completed <1 but > .66, "Knowledge Stage Completed"

elseif % Completed <.661 but > 0, "Learning Started"

elseif % Completed = 0, "Not Started"

elseif % Competed = blank/null, "Account created, Not Started"

 

 

10 REPLIES 10
jthomson
Solution Sage
Solution Sage

It'd certainly be easier to code if you trimmed down your logic, you don't need to say something is both <1 and >0.66 if you've already assigned everything that is 1 to 100% completed, similar with the next step, you just need to say >0
Greg_Deckler
Community Champion
Community Champion

Are you doing this in DAX or M? I'd use a SWITCH statement in DAX, SWITCH(TRUE()...)



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thanks Greg, always happy when I see you on a thread!

I am using DAX, and had tried the SWITCH statement.  My challenge was more around all the conditions - I'm getting a "Too many arguments were passed to the AND function.  The maximum argument count for the function is 2.".  I had hoped I had done enough isolation of the IF(AND statements to allow for this to work.  here is my formula...

 

Column = SWITCH (TRUE (), [% Completed] = 1, "100% Completed",
[% Completed] = 0, "Not Started",
(IF(AND([% Completed] < 1, [% Completed] >.66, "Knowledge Stage Completed"))),
(IF(AND([% Completed] > 0, [% Completed] <.661, "Learning Started"))),
[% Completed] = "", "Account Created, Not Started")
 
Any advice on how to fix this so I get my desired outputs?
Anonymous
Not applicable

HI @Anonymous,

 

I'd like to recommend you to use if statement to nested switch function instead of combine them in switch function, switch function not suitable to compare with data range.

Column =
IF (
    AND ( [% Completed] > 0, [% Completed] < .661 ),
    "Learning Started",
    IF (
        AND ( [% Completed] > .66, [% Completed] < 1 ),
        "Knowledge Stage Completed",
        SWITCH (
            [% Completed],
            1, "100% Completed",
            0, "Not Started",
            "", "Account Created, Not Started"
        )
    )
)

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

Thank you for this.  When I entered that formula, I got the following error:

 

Function 'SWITCH' does not support comparing values of type Number with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values.

Anonymous
Not applicable

HI @Anonymous,

 

I add value function to switch to convert value to number, maybe you can try to use following formula:

Column =
IF (
    AND ( [% Completed] > 0, [% Completed] < .661 ),
    "Learning Started",
    IF (
        AND ( [% Completed] > .66, [% Completed] < 1 ),
        "Knowledge Stage Completed",
        SWITCH (
            VALUE ( Table[% Completed] ),
            1, "100% Completed",
            0, "Not Started",
            "", "Account Created, Not Started"
        )
    )
)

 

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

Thank you.  Came back with another error - The syntax for 'Table' is incorrect. (DAX(IF ( AND ( [% Completed] > 0, [% Completed] < .661 ), "Learning Started", IF ( AND ( [% Completed] > .66, [% Completed] < 1 ), "Knowledge Stage Completed", SWITCH ( VALUE ( Table [% Completed] ), 1, "100% Completed", 0, "Not Started", "", "Account Created, Not Started" ) )))).

 

I couldn't find an expression called Table

Anonymous
Not applicable

Hi @Anonymous,

 

Table means your table name who host the column.(where [% Completed] field exists)

 

Regards,
Xiaoxin Sheng

Anonymous
Not applicable

Column =
IF (
    AND ( [% Completed] > 0, [% Completed] < .661 ),
    "Learning Started",
    IF (
        AND ( [% Completed] > .66, [% Completed] < 1 ),
        "Knowledge Stage Completed",
        SWITCH (
            VALUE ( Table[% Completed] ),
            1, "100% Completed",
            0, "Not Started",
            "", "Account Created, Not Started"
        )
    )
)

I'm now seeing a Function 'SWITCH' does not support comparing values of type Number with values of type Text error. Consider using the VALUE or FORMAT function to convert one of the values.  I tried formatting the column (which was set to Decimal Number and General) to Decimal Number and Decimal Number - didn't help.  

Anonymous
Not applicable

Doh.  Forrest for the trees....

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

Top Solution Authors
Top Kudoed Authors