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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Okazakipedro
Helper I
Helper I

ABC Catetorizing Measures, how to avoid bringing 2 categories for the same Customer (DAX)

Hello All, good morning.

 

I am stuck in a DAX measure related to ABC Customer Segmentation. My current formula is as below:

 

category_abcProfitEurr =

VAR SalesByProduct =
    CALCULATETABLE (
        ADDCOLUMNS (
            SUMMARIZE ( Fact_JobFinancials, Fact_JobFinancials[Controlling Customer Code] ),
            "@ProdSales", [job_totalProfitEur]
        ),
        ALLSELECTED ( Fact_JobFinancials )
    )
VAR AllSales =
    CALCULATE (
        [job_totalProfitEur],
        ALLSELECTED ( Fact_JobFinancials )
    )
VAR ProductsInClass =
    FILTER (
        CROSSJOIN (
            SalesByProduct,
            'Support_Category&Date'
        ),
            ([job_totalProfitEur] > 'Support_Category&Date'[ProfitLowerBoundaries]
            && [job_totalProfitEur] <= 'Support_Category&Date'[ProfitUpperBoundaries])
            ||
            ([job_totalRevenueEur] > 'Support_Category&Date'[RevenueLowerBoundaries]
            && [job_totalRevenueEur] <= 'Support_Category&Date'[RevenueUpperBoundaries])

        )
    VAR Result =
    CALCULATE (
        [job_totalProfitEur],
        KEEPFILTERS ( ProductsInClass )
    )
RETURN
    Result
 
Unfortunately this brings sometimes multiple categories for the same customer, such as 
 
Okazakipedro_0-1727179253403.png

I believe the issue is related to the or clause, for this customer, due to the revenue it falls in the A category, but due to profit in B... But I want to always return the highest one.

 

Could anyone help me?

1 ACCEPTED SOLUTION

@Okazakipedro , Check this if it meets your requirement

 

bhanu_gautam_0-1727340143725.png

 




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

5 REPLIES 5
v-kongfanf-msft
Community Support
Community Support

Hi @Okazakipedro ,


Did @bhanu_gautam reply solve your problem? If so, please mark it as the correct solution, and point out if the problem persists.

 

Best regards,

Adamk Kong

bhanu_gautam
Super User
Super User

@Okazakipedro , Try using

 

category_abcProfitEurr =
VAR SalesByProduct =
CALCULATETABLE (
ADDCOLUMNS (
SUMMARIZE ( Fact_JobFinancials, Fact_JobFinancials[Controlling Customer Code] ),
"@ProdSales", [job_totalProfitEur]
),
ALLSELECTED ( Fact_JobFinancials )
)
VAR AllSales =
CALCULATE (
[job_totalProfitEur],
ALLSELECTED ( Fact_JobFinancials )
)
VAR ProductsInClass =
FILTER (
CROSSJOIN (
SalesByProduct,
'Support_Category&Date'
),
([job_totalProfitEur] > 'Support_Category&Date'[ProfitLowerBoundaries]
&& [job_totalProfitEur] <= 'Support_Category&Date'[ProfitUpperBoundaries])
||
([job_totalRevenueEur] > 'Support_Category&Date'[RevenueLowerBoundaries]
&& [job_totalRevenueEur] <= 'Support_Category&Date'[RevenueUpperBoundaries])
)
VAR CategoryA =
CALCULATE (
[job_totalProfitEur],
KEEPFILTERS ( ProductsInClass ),
'Support_Category&Date'[Category] = "A"
)
VAR CategoryB =
CALCULATE (
[job_totalProfitEur],
KEEPFILTERS ( ProductsInClass ),
'Support_Category&Date'[Category] = "B"
)
VAR CategoryC =
CALCULATE (
[job_totalProfitEur],
KEEPFILTERS ( ProductsInClass ),
'Support_Category&Date'[Category] = "C"
)
VAR Result =
IF (
NOT ISBLANK(CategoryA), CategoryA,
IF (
NOT ISBLANK(CategoryB), CategoryB,
CategoryC
)
)
RETURN
Result




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






@bhanu_gautam  ID did not work, but I am attaching a file so you can see what is the problem, would really appreciate your inputs 🙂

 

-- Edit, it seems that I can't post the sample pbix, therefore I am writing everything here, sorry:

Fact Table (SampleData)

 

Shipment_Branch_Quarter_PKShipmentIDShipmentNojob_totalRevenueEurjob_totalProfitEurControlling Customer Code
STR-SSTR00001098-2024-Q1543A78E1-18D7-467A-BECC-52C12018DBB2SSTR000010986.880, €756,27 €ALAHLISAF
STR-SSTR00001167-2024-Q1439B06A3-E0EF-4E2C-83E7-A0CED138D27ESSTR000011670, €0, €ALAHLISAF
STR-SSTR00001167-2024-Q2439B06A3-E0EF-4E2C-83E7-A0CED138D27ESSTR00001167815.449,32 €43.503,53 €ALAHLISAF
STR-SSTR00001167-2024-Q3439B06A3-E0EF-4E2C-83E7-A0CED138D27ESSTR000011670, €-10.240,86 €ALAHLISAF
STR-SSTR00001250-2024-Q332DCA1DD-0758-45A4-86BF-DFB596B9FA1ASSTR0000125011.700, €895,97 €ALAHLISAF

 

Dimenstion (Support_Category)

 

CategoryProfitLowerBoundariesProfitUpperBoundariesRevenueLowerBoundariesRevenueUpperBoundaries
A5000010000000002500001000000000
B125005000050000250000
C-100000000012500-100000000050000


Current measure

category_abcProfitEurr =

VAR SalesByProduct =
    CALCULATETABLE (
        ADDCOLUMNS (
            SUMMARIZE ( SampleData, SampleData[Controlling Customer Code] ),
            "@ProdSales", [measure_job_totalProfitEur]
        ),
        ALLSELECTED ( SampleData )
    )
VAR AllSales =
    CALCULATE (
        [measure_job_totalProfitEur],
        ALLSELECTED ( SampleData )
    )
VAR ProductsInClass =
    FILTER (
        CROSSJOIN (
            SalesByProduct,
            'Support_Category'
        ),
            ([measure_job_totalProfitEur] > 'Support_Category'[ProfitLowerBoundaries]
            && [measure_job_totalProfitEur] <= 'Support_Category'[ProfitUpperBoundaries])
            ||
            ([measure_job_totalRevenueEur] > 'Support_Category'[RevenueLowerBoundaries]
            && [measure_job_totalRevenueEur] <= 'Support_Category'[RevenueUpperBoundaries])

        )
    VAR Result =
    CALCULATE (
        [measure_job_totalProfitEur],
        KEEPFILTERS ( ProductsInClass )
    )
RETURN
    Result



Thanks!

@Okazakipedro , Check this if it meets your requirement

 

bhanu_gautam_0-1727340143725.png

 




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Hello Bharu, thanks for the reply, but still got the same result... 

Okazakipedro_0-1727181632152.png

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.