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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Cogden
Frequent Visitor

Dynamic Segmentation of callers and calls

Hi there,

 

I was hoping someone may be able to help with a dynamic segmentation query in Power BI. 

I have an activities table (SQLActivities) which contains columns called activityID and callerID. The principle of the table is that a single callerID can have multiple activityID. I'm trying to create two pie charts to show:

 

1) Callers grouped into buckets based on number of activities per caller, and

2) Activities grouped by the same buckets for each caller. For the second pie chart I am essentially trying to show how many activities in each caller bucket -i.e. if two callers had 11 or more activities, how many activities were actually in that bucket.

 

I have created a table to specificy the values of the buckets - they are 1, 2, 3 - 5, 6 - 10, and 11 or more. I created the table as follows:

 
ActivitySegments =
Datatable(
    "Segment Key", INTEGER,
    "Bucket", String,
    "Min Activities", Integer,
    "Max Activities", Integer,
    {
        {1,"1",1,1},
        {2,"2",2,2},
        {3,"3 - 5",3,5},
        {4,"6 - 10",6,10},
        {5,"11 or more",11,99999999999}
    }
)
 
for the first chart I've been able to create a measure to show the number of callers which fall into each bucket using the following dax:
 
Activity Buckets - Callers =
VAR Summary =
    SUMMARIZE (
        FILTER(SQLActivities , SQLActivities [Filter Activities In Date] = 1),
        SQLActivities [c1_calleridid],
        "Bucket", SWITCH (
            TRUE (),
            COUNTROWS ( SQLActivities ) = 1, "1",
            COUNTROWS ( SQLActivities ) = 2, "2",
            COUNTROWS ( SQLActivities ) <= 5, "3 - 5",
            COUNTROWS ( SQLActivities ) <= 10, "6 - 10",
            COUNTROWS ( SQLActivities ) > 10, "11 or more"
        )
    )
RETURN
    SUMX ( Summary, IF ( [Bucket] = SELECTEDVALUE ( 'ActivitySegments'[Bucket] ), 1, 0 ) )
 
This seems to work well enough, but I cannot work out how to convert this to calculate the number of activities per caller bucket instead of the number of callers. The expected result would show the number of activities for callers per bucket.

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Cogden ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data. 

vtangjiemsft_0-1703061659009.png

(2) We can create measures. 

Bucket = 
var _A= COUNTROWS(FILTER(ALLSELECTED('SQLActivities'),'SQLActivities'[callerID]=MAX('SQLActivities'[callerID])))
var _bucket=SWITCH (
            TRUE (),
            _A = 1, "1",
            _A= 2, "2",
            _A <= 5, "3 - 5",
            _A <= 10, "6 - 10",
            _A > 10, "11 or more"
        )
return _bucket
Count = COUNTROWS(FILTER('SQLActivities',[Bucket] = MAX('ActivitySegments'[Bucket])))

(3) Then the result is as follows.

vtangjiemsft_1-1703061714343.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

1 REPLY 1
Anonymous
Not applicable

Hi @Cogden ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data. 

vtangjiemsft_0-1703061659009.png

(2) We can create measures. 

Bucket = 
var _A= COUNTROWS(FILTER(ALLSELECTED('SQLActivities'),'SQLActivities'[callerID]=MAX('SQLActivities'[callerID])))
var _bucket=SWITCH (
            TRUE (),
            _A = 1, "1",
            _A= 2, "2",
            _A <= 5, "3 - 5",
            _A <= 10, "6 - 10",
            _A > 10, "11 or more"
        )
return _bucket
Count = COUNTROWS(FILTER('SQLActivities',[Bucket] = MAX('ActivitySegments'[Bucket])))

(3) Then the result is as follows.

vtangjiemsft_1-1703061714343.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

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.