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
av9
Helper III
Helper III

Count of customers by dynamic segment

Hi

I am trying to group customers by 4 segements. Those who hold both Index Funds & Stocks, Index Fund Only, Stocks Only, and those who hold nothing.

 

I created a segments measure based on some conditions which gives me this output in table.

 

Total Value = SUM ( Investments[Value] )
Index Fund Value = CALCULATE ([Total Value], FILTER(Asset, Asset[Asset Type] = "Index Funds" )
Stocks Value = CALCULATE ([Total Value], FILTER(Asset, Asset[Asset Type] = "Stocks" )

 

Segments = 
SWITCH(
TRUE(),
[Index Fund Value]>0 && [Stocks Value]>0, "Index Funds & Stock",
[Index Fund Value]>0 && [Stocks Value]<=0, "Index Funds Only",
[Index Fund Value]<=0 && [Stocks Value]>0, "Stocks Only",
[Index Fund Value]<=0 && [Stocks Value]<=0, "Nothing",
BLANK())

 

The output snapshot is this:

 

av9_0-1631192905141.png

 

 

I now need to be able to count how many customers are in each segment and represent it in a bar chart that looks like this:

av9_2-1631192320019.png

So each bar would show the count of customers in each segment.

I tried to use a disconnected table but not sure how it works win this scenario. I have tried multiple techniques but cant seem to get the right measure.

 

This is the PBIX im working with.

https://drive.google.com/file/d/1r_rNN995HPC6CWIJV7zH_bDZ7QylFEFo/view?usp=sharing

 

 

1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
Community Champion

This measure seems to work:

 

Filter measure =
IF (
    ISFILTERED ( Segments[Segment] ),
    COUNTROWS (
        FILTER ( Customer, [Segments] IN { VALUES ( Segments[Segment] ) } )
    ),
    1
)

 

 

Select the table visual, add the measure to the filters for the visual in the filter pane and set the value to "is 1"
FilterSegment.gif

 

Edit: the filtering should work if you select more than one bar using ctrl





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

@av9 In general, to use a measure in that way, you need to use the Disconnected Table Trick as this article demonstrates: https://community.powerbi.com/t5/Community-Blog/Solving-Attendance-with-the-Disconnected-Table-Trick...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

I gave that a try and but couldn't quite figure it out for my sceanrio. I tried another one of your techniques I came across and it gave me a bar chart I am after, but was wandering if you knew how to ensure I can still crossfilter in the visuals in teh report. I.e you click on the bar and it filters the table?

PBIX file

av9_1-1631287758965.png

 

Count of Segment = 
VAR Segment =SELECTEDVALUE(Segments[Segment],"All")
RETURN
SWITCH(true(),
Segment="Index Funds & Stocks", COUNTX(FILTER(Customer,[Segments]="Index Funds & Stocks"),Customer[CustomerID]),
Segment="Index funds Only",COUNTX(FILTER(Customer,[Segments]="Index funds Only"),Customer[CustomerID]),
Segment="Stocks Only", COUNTX(FILTER(Customer,[Segments]="Stocks Only"),Customer[CustomerID]),
Segment="Nothing", COUNTX(FILTER(Customer,[Segments]="Nothing"),Customer[CustomerID])
)
 
 
 
PaulDBrown
Community Champion
Community Champion

This measure seems to work:

 

Filter measure =
IF (
    ISFILTERED ( Segments[Segment] ),
    COUNTROWS (
        FILTER ( Customer, [Segments] IN { VALUES ( Segments[Segment] ) } )
    ),
    1
)

 

 

Select the table visual, add the measure to the filters for the visual in the filter pane and set the value to "is 1"
FilterSegment.gif

 

Edit: the filtering should work if you select more than one bar using ctrl





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






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.