Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

How to compare two Rows value in same table and assign a value in a separate column based on it

Hi Team,

 

I need help in below logic:

 

I have three tables:
Orders table (Contains 1 row per orders placed with customer and revenue data as whole)

Order line items table (Contains brief Order data with line items bought within the order)

Product Stock Keeping Unit Table (It contains the Stock Keeping Unit and brand data)

 

Table data follows:

Order Table
Order NoCustomerRevenue
67894677Customer A580
67894600Customer B950
67890000Customer C800
67890012Customer A540

 

Order Line Items Table
Order NoProduct SKUProduct SKU CodeBrand
67894677Shampoo - 340 ml13Pantene
67894677Hair Conditioner - 340 ml11Sunsilk
67894677Hair Serum - 400ml12Matrix
67894600Shampoo - 340 ml14Sunsilk
67894600Hair Conditioner - 340 ml11Sunsilk
67894600Hair Serum - 400ml20Sunsilk
67890000Shampoo - 340 ml13Pantene
67890000Hair Conditioner - 340 ml10Pantene
67890012Hair Conditioner - 340 ml15Matrix
67890012Hair Serum - 400ml12Matrix

 

Product Stock Keeping Unit
Product SKUProduct SKU CodeBrand
Hair Serum - 400ml12Matrix
Hair Conditioner - 340 ml15Matrix
Shampoo - 340 ml13Pantene
Hair Conditioner - 340 ml10Pantene
Hair Conditioner - 340 ml11Sunsilk
Shampoo - 340 ml14Sunsilk
Hair Serum - 400ml20Sunsilk

 

What help I need is that, I want to categories my orders on the basis of Brand Name

Expected, Assign brand name to orders and if there are more than 1 brand in one order mark it as "Mix Order". Please see the expected table below:

Order Table
Order NoCustomerRevenueCalculated Brand Column
67894677Customer A580Mix Brand
67894600Customer B950Sunsilk Brand
67890000Customer C800Pantene Brand
67890012Customer A540Matrix Brand

 

Can someone please help me with the logic to create this calculated Column? I tried Compare function but it is not helping here.

  • Anonymous 
    Please use

    Column = 
    VAR Brand = CALCULATE ( SELECTEDVALUE ( 'Order Line Items'[Brand] ) )
    RETURN
        IF ( 
            ISBLANK ( Brand ),
            "Mixed Order",
            Brand
        )

10 Replies

  • tamerj1's avatar
    tamerj1
    Community Champion

    Anonymous 
    Please use

    Column = 
    VAR Brand = CALCULATE ( SELECTEDVALUE ( 'Order Line Items'[Brand] ) )
    RETURN
        IF ( 
            ISBLANK ( Brand ),
            "Mixed Order",
            Brand
        )

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you tamerj1 , this solution worked.

  • tamerj1's avatar
    tamerj1
    Community Champion

    Hi Anonymous 
    Suppose you have a one way relationhip (One to Many) between 'Orders' and 'Order Line Items' then you my try

    Calculated Brand Column =
    CONCATENATEX (
        RELATEDTABLE ( 'Order Line Items' ),
        IF (
            HASONEVALUE ( 'Order Line Items'[Brand] ),
            'Order Line Items'[Brand],
            "Mixed Order"
        )
    )
    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi tamerj1 

      I tried the solution provided by you, but in my case it is not returning the expected value. When I am applying the DAX provide by you above, it is returning the values as in the screenshot below:

       

       

      We need a little modification in the logic. 

      • tamerj1's avatar
        tamerj1
        Community Champion

        Hi Anonymous 
        Please try

        Calculated Brand Column =
        VAR Check =
            SUMX (
                RELATEDTABLE ( 'Order Line Items' ),
                IF ( HASONEVALUE ( 'Order Line Items'[Brand] ), 1 )
            )
        RETURN
            IF ( Check >= 1, VALUES ( 'Order Line Items'[Brand] ), "Mixed Order" )