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
exf048s
New Member

Trying to create buckets of percentages.. getting duplicates

I am trying to calculate "ontime%" for my clients and bucket them in 5 groups. Example is 0-64% ,65-74%, 75-84%, 85-89% and 90%+. I created a new column with the below formula. For some reason it is now duplicating my client names and putting them in multipul buckets. Any thoughts on why? 

Column- On time percent = if(' query'[Ontime_Cases] = 0, "0-64%",
if('query'[Ontime_Cases]/' query'[Received_Cases]<.65, "0-64%",
if('query'[Ontime_Cases]/' query'[Received_Cases] <.75, "65% to 74%",
if('query'[Ontime_Cases]/' query'[Received_Cases] <.85, "75% to 84%",
if('query'[Ontime_Cases]/' query'[Received_Cases] <.90, "85% to 89%",
if('query'[Ontime_Cases]/' query'[Received_Cases]>.89, "90+%","0-64%"))))))
2 ACCEPTED SOLUTIONS
lbendlin
Super User
Super User

please read about the SWITCH() statement in DAX.

View solution in original post

v-junyant-msft
Community Support
Community Support

Hi @exf048s ,

@lbendlin @samratpbi Thanks for your concern about this case and Good Answer! And I agree with @lbendlin that it would be more convenient to use SWITCH!
And this is Power Query forum, if you want to get answer by using DAX, you can post for help in the DAX or Desktop forums. And if you want to achieve your expected result by using Power Query, you can try this solution:
First, add such a custom column:

[Ontime_Cases] / [Received_Cases]

 

vjunyantmsft_0-1711614499328.png

Then add the expected custom column:

if [Percentage] < 0.65 then "0% to 64%" else if [Percentage] >= 0.65 and [Percentage] < 0.75 then "65% to 74%" else if [Percentage] >= 0.75 and [Percentage] < 0.85 then "75% to 84%" else if [Percentage] >= 0.85 and [Percentage] < 0.9 then "85% to 89%" else "90+%"

 

vjunyantmsft_1-1711614549294.png

 

Here is the whole M function in the Advanced Editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlDSUTI0UIrViVYy1TNFcCz0TBAcMz1jBMdEzwjBMUTSb4iqH0mLuZ4hlBMLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Ontime_Cases = _t, Received_Cases = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Ontime_Cases", type number}, {"Received_Cases", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Percentage", each [Ontime_Cases] / [Received_Cases]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Percentage", Percentage.Type}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type1", "Custom", each if [Percentage] < 0.65 then "0% to 64%" else if [Percentage] >= 0.65 and [Percentage] < 0.75 then "65% to 74%" else if [Percentage] >= 0.75 and [Percentage] < 0.85 then "75% to 84%" else if [Percentage] >= 0.85 and [Percentage] < 0.9 then "85% to 89%" else "90+%")
in
    #"Added Custom1"


Best Regards,
Dino Tao
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-junyant-msft
Community Support
Community Support

Hi @exf048s ,

@lbendlin @samratpbi Thanks for your concern about this case and Good Answer! And I agree with @lbendlin that it would be more convenient to use SWITCH!
And this is Power Query forum, if you want to get answer by using DAX, you can post for help in the DAX or Desktop forums. And if you want to achieve your expected result by using Power Query, you can try this solution:
First, add such a custom column:

[Ontime_Cases] / [Received_Cases]

 

vjunyantmsft_0-1711614499328.png

Then add the expected custom column:

if [Percentage] < 0.65 then "0% to 64%" else if [Percentage] >= 0.65 and [Percentage] < 0.75 then "65% to 74%" else if [Percentage] >= 0.75 and [Percentage] < 0.85 then "75% to 84%" else if [Percentage] >= 0.85 and [Percentage] < 0.9 then "85% to 89%" else "90+%"

 

vjunyantmsft_1-1711614549294.png

 

Here is the whole M function in the Advanced Editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlDSUTI0UIrViVYy1TNFcCz0TBAcMz1jBMdEzwjBMUTSb4iqH0mLuZ4hlBMLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Ontime_Cases = _t, Received_Cases = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Ontime_Cases", type number}, {"Received_Cases", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Percentage", each [Ontime_Cases] / [Received_Cases]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Percentage", Percentage.Type}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type1", "Custom", each if [Percentage] < 0.65 then "0% to 64%" else if [Percentage] >= 0.65 and [Percentage] < 0.75 then "65% to 74%" else if [Percentage] >= 0.75 and [Percentage] < 0.85 then "75% to 84%" else if [Percentage] >= 0.85 and [Percentage] < 0.9 then "85% to 89%" else "90+%")
in
    #"Added Custom1"


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

lbendlin
Super User
Super User

please read about the SWITCH() statement in DAX.

samratpbi
Resolver IV
Resolver IV

Hi, are you using Power Query? Then you may create a conditional column which us under Add Columns. If you are using conditional column then it should work properly. You may use both greater than and less than condition ( like if('query'[Ontime_Cases]/' query'[Received_Cases] >= .65 && 'query'[Ontime_Cases]/' query'[Received_Cases] <.75, "65% to 74%",) If this still doesnt work, can you please provide more details about the data?

 

This this resolves your problem then mark it as Solutions, thanks

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.

Top Solution Authors
Top Kudoed Authors