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

Multiple IFs

I have created a calculated column:

Category Sales Bin = (IF(Orders[Sale%]>0 && Orders[Sale%]<=6.00, "0% - 6%",
IF(Orders[Sale%]>6.00 && Orders[Sale%]<=14.00,"7% - 14%",
IF(Orders[Sale%]>14.00 && Orders[Sale%]<=21.00,"14% - 21%",
IF(Orders[Sale%]>21.00,"> 21%" )))))
 
sale% is also a calcualted column which is calculating percentage and is in decimal format.
Now Category Sales Bin is showing "0% - 6%" for all the values
For 13.01 or 12.68 it is showing "0% - 6%".
 
Why it is showing for all same value
 
Image:Link 
5 REPLIES 5
Sumanth_23
Memorable Member
Memorable Member

hi @Anonymous - you can try with the below formula

Category Sales Bin =
(
IF (
Category_Sales[Sales %] > 0
&& Category_Sales[Sales %] <= 0.06,
"0% - 6%",
IF (
Category_Sales[Sales %] > 0.06
&& Category_Sales[Sales %] <= 0.14,
"7% - 14%",
IF (
Category_Sales[Sales %] > 0.14
&& Category_Sales[Sales %] <= 0.21,
"14% - 21%",
IF ( Category_Sales[Sales %] > 0.21, "> 21%" )
)
)
)
)
 
Multiple IFs.png
 
Please mark the above comment as a solution to help others find it more quickly. Also please provide a 👍 if my comment helped with solving your issue. Thanks!
Did I answer your question? Mark my post as a solution! Appreciate your Kudos!

Proud to be a Super User!



While the code based approach using complex nested IF statements will work, I usually prefer a DATA based approach:

1) Create a small table (maybe use ENTER DATA) that contains the following: Sort Order (INT), Low Range, High Range, Description.

2) Add data as needed: 1 , 0, 0.06, "0% - 6.00%", etc.

3) Set the Sort By of Descripiton to the Sort Order column.

4) Hide the table. It needs no relationships.

5) Add a column with a formual like this:

 

Category Sales Bin = CALCULATE ( VALUES ( 'Lookup Table'[Description]),

                                 FILTER ( 'Lookup Table',

                                       'Lookup Table'[Low Range] <= 'Main Table'[Sales%]

                                  &&

                                       'Lookup Table'[High Range] >= 'Main Table'[Sales%]

                                            )

                                     )

 

Now you have a solution that is DATA driven. Put that table in an EXTERNAL source like a CSV, Excel, or database table and you can change the bins by changing the DATA, not having to touch the CODE.

                                  

 




Did I answer your question? If so, mark my post as a solution. Also consider helping someone else in the forums!

Proud to be a Super User!





Anonymous
Not applicable

@Sumanth_23  @ToddChitt ,

 

I have made the changes but it is still showing same.

 

Attching the Power bi file.

 

File:Link 

Ah, because you need it to be a MEASURE, not a COLUMN. 

From what I see, every sale in Product Sub Category of Appliances has a Category Sales Bin of "0% - 6.00%" so your table is doing a GROUP BY of that text value.




Did I answer your question? If so, mark my post as a solution. Also consider helping someone else in the forums!

Proud to be a Super User!





ToddChitt
Super User
Super User

Because in the first line: 6.00 is just that. Six. It is NOT six PERCENT. You need 0.06.




Did I answer your question? If so, mark my post as a solution. Also consider helping someone else in the forums!

Proud to be a Super User!





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.