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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
Bernie6808
Frequent Visitor

Grouping by value

Hi - First post on here, and I'm quite new to Power BI... I am trying to group values into a new column and have created the following 'M' code which seem to work... I just wonder if there is a more elegant way to acheive the same result?

 

= Table.AddColumn(#"Removed Columns3", "Application Bucket", each if [Application Income] < 4999 then "Under 5K"
else
if [Application Income] < 10000 then "5K - 10K"
else
if [Application Income] < 50000 then "10K - 50K"
else
if [Application Income] < 100000 then "50K - 100K"
else
if [Application Income] < 500000 then "100K - 500K"
else
if [Application Income] < 1000000 then "500K - 1M"
else
if [Application Income] < 3000000 then "1M - 3M"
else "3M +")

 

1 ACCEPTED SOLUTION
jbwtp
Memorable Member
Memorable Member

Hi @Bernie6808,

 

Alternatively (please note slight change in how the rules are formulated):

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjUwMFCK1YlWMjRAYQGZsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Application Income" = _t]),
    
    rules = {
                {0, "Under 5K"},
                {5000, "5K - 10K"},
                {10000, "10K - 50K"},
                {50000, "50K - 100K"},
                {100000, "100K - 500K"}
    },
    
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Application Income", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Application Bucket", (x)=>List.First(List.Select(rules, each _{0} >= x[Application Income])))
in
    #"Added Custom"

Cheers,

John

View solution in original post

4 REPLIES 4
Bernie6808
Frequent Visitor

Thanks John, I'll give this a go.

 

ImkeF
Community Champion
Community Champion

Hi @Bernie6808 ,
good that you asked - there is indeed a georgeous method that you will probably like. It also allows you to keep your ranges in a nice table apart from the code that you can adjust much simpler if needed:
VLOOKUP-True Equivalent in Power Query with Dynamic Tiers - YouTube

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Thanks very much for your reply - I will try this and get back to you!

jbwtp
Memorable Member
Memorable Member

Hi @Bernie6808,

 

Alternatively (please note slight change in how the rules are formulated):

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjUwMFCK1YlWMjRAYQGZsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Application Income" = _t]),
    
    rules = {
                {0, "Under 5K"},
                {5000, "5K - 10K"},
                {10000, "10K - 50K"},
                {50000, "50K - 100K"},
                {100000, "100K - 500K"}
    },
    
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Application Income", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Application Bucket", (x)=>List.First(List.Select(rules, each _{0} >= x[Application Income])))
in
    #"Added Custom"

Cheers,

John

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.