Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
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?
Solved! Go to Solution.
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" )
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.
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" )
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 v-xuding-msft did.
For anyone wondering about the order of the statements:
It matters because the first statement that matches the criteria get used. See this blog post:
https://powerpivotpro.com/2015/03/the-diabolical-genius-of-switch-true/
"Aha! So the FIRST test case that matches, gets used"
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" )
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
123 | |
78 | |
49 | |
38 | |
37 |
User | Count |
---|---|
196 | |
80 | |
70 | |
51 | |
42 |