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
cris007
Frequent Visitor

Dax formula comparing one row to each other rows per group

Hello Community, 

 

I have the data below:

BrandClientTypeValue
AAABTCMy brand5000
BBBBTCcompetitor7000
CCCBTCcompetitor4000
AAABTCMy brand500
BBBBTCcompetitor8000
CCCBTCcompetitor800
AAAB&BMy brand8000
BBBB&Bcompetitor900
CCCB&Bcompetitor10000

 

 

I am looking for a DAX formula that would say : Per client, IF the value of "My brand"  is bigger than at least one of the competitor's value , than return "--"; IF the value of "My brand"  is bigger than the value of each competitors, than return "ok" ; IF the value of "My brand"  is smaller than the value of each competitors, than return "nok".

 

For example, for the client B&B, I will compare the value of the brand AAA (which is my brand) separetly to the value of BBB and CCC. My formula should return "--" since the value of AAA is bigger than at least one of the competitor for the client B&B. 

 

Thanks for the help

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

@cris007 
Please refer to attached sample file with a preliminary solution. Please check the file and amended with correct data sample if needed and advise exactly how do you want display the results either a calculated column or a measure and the shape of the report.

1.png

Flag = 
VAR CurrentProductClientTable = 
    CALCULATETABLE ( 
        'Table',
        ALLEXCEPT ( 'Table', 'Table'[Product Name], 'Table'[Client] )
    )
VAR MyBrandValue =
    SUMX ( 
        FILTER ( 
            CurrentProductClientTable,
            'Table'[Type] = "My brand"
        ),
        'Table'[Value]
    )
VAR CompetotorTable = FILTER ( CurrentProductClientTable, 'Table'[Type] = "competitor" )
VAR MaxCompetitorValue = MAXX ( CompetotorTable, 'Table'[Value] )
VAR MinCompetitorValue = MINX ( CompetotorTable, 'Table'[Value] )
RETURN
    SWITCH ( 
        TRUE ( ),
        MyBrandValue > MaxCompetitorValue, "Ok",
        MyBrandValue > MinCompetitorValue, "--",
        "NOk"
    )

View solution in original post

7 REPLIES 7
tamerj1
Super User
Super User

@cris007 
Please refer to attached sample file with a preliminary solution. Please check the file and amended with correct data sample if needed and advise exactly how do you want display the results either a calculated column or a measure and the shape of the report.

1.png

Flag = 
VAR CurrentProductClientTable = 
    CALCULATETABLE ( 
        'Table',
        ALLEXCEPT ( 'Table', 'Table'[Product Name], 'Table'[Client] )
    )
VAR MyBrandValue =
    SUMX ( 
        FILTER ( 
            CurrentProductClientTable,
            'Table'[Type] = "My brand"
        ),
        'Table'[Value]
    )
VAR CompetotorTable = FILTER ( CurrentProductClientTable, 'Table'[Type] = "competitor" )
VAR MaxCompetitorValue = MAXX ( CompetotorTable, 'Table'[Value] )
VAR MinCompetitorValue = MINX ( CompetotorTable, 'Table'[Value] )
RETURN
    SWITCH ( 
        TRUE ( ),
        MyBrandValue > MaxCompetitorValue, "Ok",
        MyBrandValue > MinCompetitorValue, "--",
        "NOk"
    )

many thanks for your help @tamerj1 

cris007
Frequent Visitor

Hi @tamerj1 , thanks for your reply.

 

Yes sure:

 

for the client BTC , the formula should return "--" since the value of my brand (AAA) is bigger than at least one competitor's value but not all of them. 

 

An exemple for the formula returning "ok" woul be as below:

BrandClientTypeValue
AAABTCMy brand15.000
BBBBTCcompetitor9000
CCCBTCcompetitor8000

 

 

And an exemple for the formula returning "ok" would be as below:

BrandClientTypeValue
AAABTCMy brand2000
BBBBTCcompetitor3000
CCCBTCcompetitor4000

 

 

@cris007 

Does each of these two examples represent a different date or what exactly?

@tamerj1 no it is for one single date. there is no calendar in this case. 

@cris007 

Apparently I failed to properly express my question. 
If not date what gropus each "My Brand" with its relevant "Competitors" then what is? What other column(s) do you have in the table?

tamerj1
Super User
Super User

Hi @cris007 

Can describe the same example but for BTC?

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.