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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
adriancho_BI
Regular Visitor

Create Category from numeric field

Hello! I'm trying to create a simple categry with the next logic, but I don't see the category "0%" and I don't know how to make ir appear. For devices with this field = 0.00 shows me the next category ">0 -25%".
This is a Custom Column in Power BI, no Power Query, and I'm using DirectQuery:

%_Range_Column =
SWITCH (
    TRUE(),
data_device[%_days_with_traffic] = 0.00, "0%",
data_device[%_days_with_traffic] <= 0.25, ">0 -25%",
data_device[%_days_with_traffic] <= 0.5, ">25 -50%",
data_device[%_days_with_traffic] <= 0.75, ">50 -75%",
data_device[%_days_with_traffic] > 0.75, ">75-100%",
"0%" )
A sample of my data is:
Device_ID%_days_with_traffic%_Range_Column
A0.00>0 -25%
B0.26> 25-50%
C0.502> 50 -75%


4 REPLIES 4
Anonymous
Not applicable

Hi @adriancho_BI ,

Given the logic you've shared, your function syntax appears correct for the intended categorization.
Sometimes, due to the way floating-point numbers are represented, a value that appears as might not be exactly zero. Consider adding a small tolerance in your comparison to catch these cases, such as the method Greg provided.
Finally, please try changing the data type of [%_days_with_traffic] to Fixed decimal number.
Data types in Power BI Desktop - Power BI | Microsoft Learn

vcgaomsft_0-1710913355676.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly--How to provide sample data in the Power BI Forum--China Power BI User Group

Thank you for the response, but it didn't work, is so strange.

Greg_Deckler
Super User
Super User

@adriancho_BI Could be a decimal precision issue. Try this:

%_Range_Column =
SWITCH (
    TRUE(),
data_device[%_days_with_traffic] < 0.001, "0%",
data_device[%_days_with_traffic] <= 0.25, ">0 -25%",
data_device[%_days_with_traffic] <= 0.5, ">25 -50%",
data_device[%_days_with_traffic] <= 0.75, ">50 -75%",
data_device[%_days_with_traffic] > 0.75, ">75-100%",
"0%" )


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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Thanks for the answer! But I've already tried that approach without any change 😞

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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