Forum Discussion
Creating groups based on numbers
- 9 years ago
Select the table/query in question. Hit "Edit Queries".
In there, you have option to add blank query. Do so and go to Advanced Editor.
Paste in "M" as below (you can adjust range as needed or add more arugments).
(vals) => let ValBucket = { {(x)=>x<10, "0-9 members"}, {(x)=>x<25, "10-24 members"}, {(x)=>x<50, "25-49 members"}, {(x)=>true, "50+ members"} }, Result = List.First(List.Select(ValBucket, each _{0}(vals))){1} in ResultOnce confirmed, rename the query to something that makes sense (Ex. BucketFunc).
Now, still in Query Editor, go back to your table where you want to add custom buckets/bands.
In "Add column" ribbon tool, select "Invoke Custom Function".
Choose a name for the column and select "BucketFunc" you just created. "vals" should be column where the values you want to band belongs.
Result should look like below.
- 9 years ago
aksl,
You could also use DAX to add a calculated column.
Group Name = SWITCH ( TRUE (), Table1[column X] >= 0 && Table1[column X] <= 9, "0-9 members", Table1[column X] >= 10 && Table1[column X] <= 24, "10-24 members", "other" )
Thanks for your response, Chihiro. I follow the concept, but I still don't see that PowerBI has the functionality to execute this. Am I missing something?
I could do it in Excel, but I am trying to create something that is dynamic, so would like to be able to do it in BI if possible.
Select the table/query in question. Hit "Edit Queries".
In there, you have option to add blank query. Do so and go to Advanced Editor.
Paste in "M" as below (you can adjust range as needed or add more arugments).
(vals) =>
let ValBucket =
{
{(x)=>x<10, "0-9 members"},
{(x)=>x<25, "10-24 members"},
{(x)=>x<50, "25-49 members"},
{(x)=>true, "50+ members"}
},
Result = List.First(List.Select(ValBucket, each _{0}(vals))){1}
in
ResultOnce confirmed, rename the query to something that makes sense (Ex. BucketFunc).
Now, still in Query Editor, go back to your table where you want to add custom buckets/bands.
In "Add column" ribbon tool, select "Invoke Custom Function".
Choose a name for the column and select "BucketFunc" you just created. "vals" should be column where the values you want to band belongs.
Result should look like below.
- sotoc7 years agoAdvocate I
I need to do this using only Direct Query mode. My employee counts have ranges that are not eligible for binning. Any help is appreciated.
Customer #Employees Category A 15 10 to 25 B 10 10 to 25 C 4 0 to 5 D 2 0 to 5 E 2 0 to 5 F 0 0 to 5 G 8 6 to 9 - biswad7 years agoAdvocate IHi friend, use SWITCH function , it helped me. You can find the solution on my post.
- Gabrielfranco7 years agoFrequent Visitor
Hi mate,
did u got a solution to this kind categorization? I'm trying to do something like that as well.
- ChihiroK7 years agoRegular Visitor
Alternate to what biswad wrote, if you are using SQL statement in your Direct Query...
You can use CASE WHEN statement to create the column during query, rather than adding calculated column using DAX.
Or if you have the rights, you could just create View/Stored Proc with the column in SQL side and import as is.
- Anonymous6 years agoNot applicable
Awesome, learned something new today
- Anonymous3 years agoNot applicable
I am creating a table like no. of accounts and Delay Payments(in no. of days).
What if I want something like.
Delay Payments(in days) No. of Accounts
0+ 5000
30+ 3800
60+ 2700
90+ 2300
So on... Is it possible in Power Bi