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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

IF Formula Help AGAIN

Hi.

 

I am trying to categorise numerial responses into 3 different categories.

 

If they answered betweeb 0-1 - I want to categorise that as 0-1 Day Active

If they answered between 2-4 - I want to categorise that as 2-4 Days Active

If they answered between 5-7 - I want to categorise that as 5+ Days Active

If the box is not filled - I don't want it to categorise

 

See the example of my data set below, the column in bold is what I need.

NameAnswerCatergory
Mary22-4 Active
Joe55+ Active
John  
 
I have tried the below DAX and it works except it categories when a cell is left blank where it hasnt been answered as 0-1 Active. Is there a way to alter the dax below so it doesn't categorise the blank cells?
 
Ans_Cat = if ('Table'[Answer] <=1, "0-1 Active", IF(AND('Table'[Answer] >=2,'Table'[Answer] <=4), "2-4 Active", "5+ Active")
 
1 ACCEPTED SOLUTION

@Anonymous ,

I suppose your Answer column is of Number type.

If you need a calculated column, then 

 

Ans_Cat_cln = 
SWITCH (
    TRUE (),
    ISBLANK(T[Answer]), BLANK (),
    T[Answer] <= 1, "0-1 Active",
    T[Answer] <= 4, "2-4 Active",
    "5+ Active"
)

 

If you need a measure, then

 

#Ans_Cat = 
VAR currentAnswer = MAX ( T[Answer] )
RETURN
    IF (
        HASONEVALUE ( T[Answer] ),
        COALESCE (
            SWITCH (
                TRUE (),
                ISBLANK(currentAnswer), BLANK (),
                currentAnswer <= 1, "0-1 Active",
                currentAnswer <= 4, "2-4 Active",
                "5+ Active"
            ),
            ""
        )
    )

 

ERD_0-1623231632372.png

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

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

View solution in original post

11 REPLIES 11
PaulDBrown
Community Champion
Community Champion

Try

For a calculated column:

Ans_Cat =
SWITCH(TRUE(),

ISBLANK(Table [Answer]), BLANK(),

Table[Answer] <= 1, "0-1 Active",

Table [Answer] <=4, "2-4 Active",

"5+ Active")

 

If you need this as a measure, you will need to wrap the expression with SUM, as in SUM(Table[Answer])





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

Hi @PaulDBrown 

 

It didn't seem to work... it said I had too many agruements in place but I can't figure out where!

What is the data type for the column Table[answer]?

Also, are you adding this as a calculated column to a table or are you creating a measure?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

Thank you so much!!

ERD
Super User
Super User

Hi @Anonymous ,

You can try this:

Ans_Cat = if (AND('Table'[Answer] <=1, 'Table'[Answer] <> BLANK() ), "0-1 Active", IF(AND('Table'[Answer] >=2,'Table'[Answer] <=4), "2-4 Active", "5+ Active")

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

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Anonymous
Not applicable

Hi @ERD 

 

Thanks for this but when I used it, it seemed to now categorise the blank cells as "5+ Active" instead of just returning it blank.

@Anonymous ,

True, sorry, here is a small change if you still want to use IF statements (I would use SWITCH). 

Ans_Cat_cln =
IF (
    AND ( 'T'[Answer] <= 1, 'T'[Answer] <> BLANK () ),
    "0-1 Active",
    IF (
        AND ( 'T'[Answer] >= 2, 'T'[Answer] <= 4 ),
        "2-4 Active",
        IF ( AND ( 'T'[Answer] >= 5, 'T'[Answer] <= 7 ), "5+ Active" )
    )
)

ERD_0-1623229101469.png

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

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Anonymous
Not applicable

Hi @ERD 

 

If you think SWITCH would be better, how would I rewrite the DAX? Sorry I am a complete beginner and just finding my feet with this!

@Anonymous ,

I suppose your Answer column is of Number type.

If you need a calculated column, then 

 

Ans_Cat_cln = 
SWITCH (
    TRUE (),
    ISBLANK(T[Answer]), BLANK (),
    T[Answer] <= 1, "0-1 Active",
    T[Answer] <= 4, "2-4 Active",
    "5+ Active"
)

 

If you need a measure, then

 

#Ans_Cat = 
VAR currentAnswer = MAX ( T[Answer] )
RETURN
    IF (
        HASONEVALUE ( T[Answer] ),
        COALESCE (
            SWITCH (
                TRUE (),
                ISBLANK(currentAnswer), BLANK (),
                currentAnswer <= 1, "0-1 Active",
                currentAnswer <= 4, "2-4 Active",
                "5+ Active"
            ),
            ""
        )
    )

 

ERD_0-1623231632372.png

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

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Anonymous
Not applicable

This is great thank you.

 

Also one last thing, people have responded with 0 as an answer but it is now reading it as a blank cell and isn't categorising the number. 0 is a valid answer as I want it to categorise as 0-1 Active?



@Anonymous ,

I've changed the previous code a bit. Please, try again.

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

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.