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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Jimmy_85
New Member

Measure segmentation in ranges based on another table

Dear All,

 

I need your help to the below: I have a classic database (Input table 1) with Sales/Cost data with different hierarchy levels for product and geography. The first step is to calculate the Gross Margin (GM) as calculated measure (defined as 1-Cost/Sales). On top I have another input table (Input table 2) which classifies the status of a product category based on the GM. The two desired tables are: Output table 1: A color coding indicating the status of the GM (I managed till now with switch/true but without the product category dimension in input table 2). Output table 2: Indicate the % of sales that are under each GM status. I managed this with the formula at the bottom, but again without the product category dimension. Of note that both output tables need to have the capability of drill up/drill down for both geography and product hierarchies.

 

Thanks a million, 

Jimmy

 

 

Input Tables
      
Table 1: Simple Database     
CountryProduct SectorProduct CategorySKUSalesCost
Country XFruitsBanana4242105
Country YVegetablesTomato323386
Country YFruitsApples85782012
Country YVegetablesCucumber948982
Country ZFruitsApples8578104
Country ZVegetablesCucumber94892010
      
Table 2: Gross Margin% Range of a calculated measure    
Product Category StatusUpper LimitLower Limit  
ApplesGreen100%50%  
ApplesRed50%30%  
CucumberGreen10060%  
CucumberRed60%30%  
      
      
Desired Output
      
Table 1: Color Coding based on Gross Margin%   
Product CategoryCountry YCountry Z   
ApplesRedGreen   
CucumberGreenRed   
      
Table 2: % Sales under different GM% Status   
Product CategoryGreenRedTotal  
Apples33%67%100%  
Cucumber29%71%100%  

 

 

 

GM% Cluster =

CALCULATE (sum(Table1[Sales]),

    FILTER (

        VALUES (Table1) ,

        COUNTROWS (

            FILTER (

                'Table2',

                [GM%]>= 'Table2'[Lower Limit]

                && [GM%] < 'Table2'[Upper Limit]

            )

        ) > 0

    )

)

3 REPLIES 3
v-zhenbw-msft
Community Support
Community Support

Hi @Jimmy_85 ,

 

We can use the following steps to meet your requirement.

 

1. Create a GM calculate column in Table1.

 

GM = 1 - DIVIDE([Cost],[Sales])

 

Measure 1.jpg

 

2. Create a country column in Table2.

 

country = CALCULATE(MAX('Table1'[Country]),FILTER('Table1','Table1'[Product Category]='Table2'[Product Category ] && 'Table1'[GM]>='Table2'[Lower Limit] && 'Table1'[GM]<='Table2'[Upper Limit]))

 

Measure 2.jpg

 

Then we can get the output table1.

 

Measure 3.jpg

 

3. We need to create a column in Table2 to calculate the sales.

 

Sales = CALCULATE(SUM(Table1[Sales]),FILTER('Table1','Table1'[Product Category]='Table2'[Product Category ] && 'Table1'[GM]>='Table2'[Lower Limit] && 'Table1'[GM]<='Table2'[Upper Limit]))

 

Measure 4.jpg

 

4. At last we can create a measure and get the output table2.

 

GM% Cluster = 
VAR total =
    CALCULATE (
        SUM ( Table1[Sales] ),
        FILTER (
             Table1 ,
            COUNTROWS (
                FILTER (
                    ALLSELECTED('Table2'),
                    [GM] >= 'Table2'[Lower Limit]
                        && [GM] < 'Table2'[Upper Limit]
                )
            ) > 0
        )
    )
var each_s = CALCULATE(SUM(Table2[Sales]))
RETURN
DIVIDE(each_s,total)

 

Measure 5.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

BTW, pbix as attached.       

 

Best regards,

 

Community Support Team _ zhenbw

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

 

 

Hello All,

 

Thank you very much for your quick responses! 

 

@amitchandak unfortunately this was my first effort but didn't finally work

 

@v-zhenbw-msft thank you for the detailed effort - please see below why this solution cannot work:

  • GM% cannot be in a calculated column as I need this as a measure not a by row calculation. My original database has 20 countries, 5 product sectors, 50 product categories and 3,000 SKUs. And I need to do this calculation at any level of selection. 
  • Due to the complexity of the database I cannot use the GM% range table to assign next to it the Country and the GM%. 
  • In your final output 2 table, the total by row should be 100%. The logic is what % of Sales is under Red and under Green status, hence the sum should be 100%. 
  • The desired output tables are exactly the ones that I have put above, with only difference that I have originally a much bigger database vs. this simplistic one. 

Thank you!

amitchandak
Super User
Super User

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.