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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
CobraKAI
Frequent Visitor

SWITCH or IF that groups all negative values and blanks

Hello,
I have worked on creating a SWITCH or IF function that groups certain values into groups with a category name. I am having trouble of getting all negative values and blanks into the same group. This is what I have so far. What am I doing wrong?

SWITCH(
TRUE(),
Members[Age] >=0 && Members[Age]<=15 , "Child",
Members[Age] >15 && Members[Age]<=26 , "Youth",
Members[Age] >26 , "Adult",
Members[Age] <0 && ISBLANK(Members[Age]), "Faulty age" )
 
And my IF function attempt:

IF(Members[Age] >=0 && Members[Age] <=15, "Child",
IF( Members[Age] >15 && Members[Age] <=26, "Youth",
IF(Members[Age] >26, "Adult",
IF(ISBLANK(Members[Age]) && Members[Age]<0, "Faulty age","Faulty age")
)
)
)
1 ACCEPTED SOLUTION
v-xuding-msft
Community Support
Community Support

Hi @CobraKAI ,

As az38 suggested, you need to change "&&" to "||". And you also should judge "Faulty age" firstly. Please try this.

Column = SWITCH(
TRUE(),
'Members'[Age] <0 || ISBLANK('Members'[Age]), "Faulty age",
'Members'[Age] >=0 && 'Members'[Age]<=15 , "Child",
'Members'[Age] >15 &&'Members'[Age]<=26 , "Youth",
'Members'[Age] >26 , "Adult",
"Faulty age" )

 2.PNG

Best Regards,

Xue Ding

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

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-xuding-msft
Community Support
Community Support

Hi @CobraKAI ,

As az38 suggested, you need to change "&&" to "||". And you also should judge "Faulty age" firstly. Please try this.

Column = SWITCH(
TRUE(),
'Members'[Age] <0 || ISBLANK('Members'[Age]), "Faulty age",
'Members'[Age] >=0 && 'Members'[Age]<=15 , "Child",
'Members'[Age] >15 &&'Members'[Age]<=26 , "Youth",
'Members'[Age] >26 , "Adult",
"Faulty age" )

 2.PNG

Best Regards,

Xue Ding

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

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

It was so easy and small so now I feel stupid. Thanks for the help!

But why does the order of the statements matter? The first reply in this thread didnt solve my issue with blank rows but  

 

For anyone wondering about the order of the statements:

az38
Community Champion
Community Champion

Hi @CobraKAI 

try OR, not AND

Members[Age] <0 || ISBLANK(Members[Age])

 

SWITCH(
TRUE(),
Members[Age] >=0 && Members[Age]<=15 , "Child",
Members[Age] >15 && Members[Age]<=26 , "Youth",
Members[Age] >26 , "Adult",
Members[Age] <0 || ISBLANK(Members[Age]), "Faulty age",
"Faulty age" )

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

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

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