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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
KPau
Frequent Visitor

Count customers from a group, while removing filter on said group

Hi everyone,

 

I've been trying to figure this one out, unsuccessfully.

 

I have a facts table which countains a billing amount per Customer and per month. Months are pivoted so that billing amounts are stored in each column for each month. A customer belongs to an internal classification, which can change overtime (Customer 1 may belong to group A in january but be attached to group B in february). My table looks like this :

 

GroupCustomer_IDBilling202305Billing202304...Billing202205...flag last year
A100 100 1
B1120110 0 1
A22020 0 0
A33030 30 1
B400 500 1

 

I need to figure out, for a given month, how many customers were billed said month and, AMONG THEM, how many customers are still billed exactly one year later. This will allow me to calculate a rate : (number of billed customers same month last year - number of billed customers this month) / number of billed customers same month last year.

The field "Flag last year" equals 1 if a customer was billed the same month a year before, regardless of the group they belong to.

 

So, in my example, my output should be this :

MonthNumber of billed Customers in 2022-05Among them, number of customers still billed in 2023-05Rate
2023-05 vs 2022-053 (id 1;3;4)2 (id 1 and 3)33%

 

I managed to get this part to work by defining variables, which count distinct Customers for each month, and then using a SWITCH function to determine which variable is to be displayed in the table.

 

My problem now is that users need to filter by Group. And, as I mentioned, a Customer can change groups overtime. However, users want to count Customers, regardless of their groups.

In my example, this means that if a user filters on group A, the diplayed rate should count customer 1 on both 2022-05 and 2023-05 periods, not only on 2022-05.

 

How to get there ? I mean, if they select a group, my table gets filtered and the measure cannot take into consideration my second row anymore. If I use a REMOVEFILTERS function, I loose the information of the group that was filtered on.
So here is how my measure should work : "you filtered on group A : here is the list of customers that belong to that group. Among these customers, here is how many are still billed one year later".

I figured perhaps I should use a SUMMARIZE funciton but I'm not confident on that and still wouldn't know how to build the measure.

 

I hope this makes sense, thanks a lot for your help

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @KPau 

 

Is your source data as shown in the diagram?

vzhangti_0-1688104482951.png

Measure:

Number of billed Customers in 2022-05 = CALCULATE(COUNT('Table'[Customer_ID]),FILTER(ALL('Table'),[Date]=DATE(2022,5,1)))
Number of customers still billed in 2023-05 = 
Var _table=CALCULATETABLE(VALUES('Table'[Customer_ID]),FILTER(ALL('Table'),[Date]=DATE(2022,5,1)))
Return
CALCULATE(COUNT('Table'[Customer_ID]),FILTER(ALL('Table'),[Date]=DATE(2023,5,1)&&[Customer_ID] in _table))
Rate = DIVIDE([Number of billed Customers in 2022-05]-[Number of customers still billed in 2023-05],[Number of billed Customers in 2022-05])

vzhangti_1-1688105128915.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

2 REPLIES 2
v-zhangti
Community Support
Community Support

Hi, @KPau 

 

Is your source data as shown in the diagram?

vzhangti_0-1688104482951.png

Measure:

Number of billed Customers in 2022-05 = CALCULATE(COUNT('Table'[Customer_ID]),FILTER(ALL('Table'),[Date]=DATE(2022,5,1)))
Number of customers still billed in 2023-05 = 
Var _table=CALCULATETABLE(VALUES('Table'[Customer_ID]),FILTER(ALL('Table'),[Date]=DATE(2022,5,1)))
Return
CALCULATE(COUNT('Table'[Customer_ID]),FILTER(ALL('Table'),[Date]=DATE(2023,5,1)&&[Customer_ID] in _table))
Rate = DIVIDE([Number of billed Customers in 2022-05]-[Number of customers still billed in 2023-05],[Number of billed Customers in 2022-05])

vzhangti_1-1688105128915.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

Hi @v-zhangti ,

Thanks for your help. This method indeed worked fine in my Power BI Desktop, but not in Power BI Service.

 

My source data does not quite fit your screeshot, as it is pivoted on the date column. It looks like this instead :

KPau_0-1688476684530.png

 

But by adapting the formula a bit (using Billing202205 > 0 instead of date=2022-05), it worked like a charm... in Power BI Desktop.

 

However, when published to the service, the report will show a "visual has exceeded available resources" error. I simplified the dataset for my example but I have many, many customers that very frequently change billing groups, and I have to retrieve data for 36 months... 

 

I tried to create anoter facts table which showed Customers and Billing amounts (still with month in columns), and then implement an N-N relationship between my current facts table and this one, on customer_id, but resources are still exceeded that way. 

Is this request too heavy for Power BI to process or should I search for a work-around ?

 

Thanks again for your help

Regards

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors