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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Clustering and Segmentation for subelements of Dataset within PowerBI

Hi together,

you already helped me once so I hope you might have a solution to my problem.

I already have a working formula that clusters my revenue and margin for the chart seen below sothat I can calculate that e.g. Customer 1 makes 190 revenue and Customer 2 125 revenue. I was also able to calculate an overal Margin for each customer (e.g. Customer 1 has 120/190 = 63%).

 

My Problem:

Now I want to have the margin specified to each department and later each year. Within my company I have such a dataset and already created several PBI Pages for each department. The Problem I have is that when I create a slicer for the margin it always applies to the overall margin of the customer across all department and across all years.

 

Is it possible to specify the formula for the profit margin in a way that it either only applies for the page filters (for example when I have a page for Department A it calculates the margin in % only for Department A)? Or is it possible within the dataset to create multiple calculations for Department A, Department B and Department C - if so: how do I have to specify my formula in DAX language?

I add the solution for the margin I currently have from another user (with no specification for the department here):

Margin total % = CALCULATE(DIVIDE(SUM('Table'[Margin]),SUM('Table'[Revenue])),ALLEXCEPT('Table','Table'[Customer ]))
cluster margin group = 
SWITCH(TRUE(),'Table'[Margin total %]>0.4,"Great",'Table'[Margin total %]>0.3&&'Table'[Margin total %]<=0.4,"Good",'Table'[Margin total %]<0.3,"Bad",BLANK())


How do I apply the formula only to a certain page filter. More concrete how can I easily create a A, B, C segmentation for Department A, Department B, Department C ? I also realized that I need this formula in order to classify the top customers for each year and not overall for multiple years as my dataset shows all revenues within one file (here a short table for clarification):

 

CustomerRevenueMarginYearMonthDepartment
Customer 1

20

102017...Department A
Customer 250152017

...

Department B
Customer 31052017...Department A
Customer 180

50

2017

...Department C
Customer 220152018...Department A
Customer 315102018......
Customer 190602019......
Customer 255202019......
Customer 33002019......

 

So the goal is to afterwards apply the A, B, C segmentation for each Department and for each year. Do I need multiple calculated columns therefore?

 

I am sorry that I so consultation-intensive, but after this question I am really happy and satified

1 REPLY 1
Anonymous
Not applicable

@Anonymous

 

Try edit the margin total% measure include the filters on Customer and Department using Earlier。

 

 

Margin total % = CALCULATE(DIVIDE(SUM('Table'[Margin]),SUM('Table'[Revenue])),filter(all(table),sumx(filter(table, earlier('Table'[Customer])='Table'[Customer]),1),filter(all(table),sumx(filter(table, earlier('Table'[Department])='Table'[Department]),1))

 

 

 

Paul Zheng _ Community Support Team
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors