Forum Discussion

zbeg's avatar
zbeg
Frequent Visitor
5 years ago
Solved

DAX Measure breaks relationship

Hello Power BI community,

 

I have two tables for my pizza business. Customers submit an order in the PizzaOrderForm table. I have a second table, Pizza, which uses a measure to see what's missing.

 

Pizza:

OrderIDCrustSauceCheeseTopping
100ThinRedMozzarellaMushrooms
101FlatbreadWhiteMozzarellaPepperoni
102Thin Havarti 
103 RedMozzarellaCheese
104Deep dishRedFontina 

 

PizzaOrderForm:

Form_OrderIDForm_CrustForm_SauceForm_CheeseForm_Toppping
100ThinRedMozzarellaMushrooms
101FlatbreadWhiteMozzarellaPepperoni
102ThinBlueHavartiAnchovies
103StuffedRedMozzarellaCheese
104Deep dishRedFontinaPeppers

 

I am using the following measure to look at the table Pizza to see what I'm missing:

 
Still Needs = 
VAR __ItemsFound =
{
("Crust",MAX(Pizza[Crust])),
("Sauce",MAX(Pizza[Sauce])),
("Cheese",MAX(Pizza[Cheese])),
("Topping",MAX(Pizza[Topping]))
}

VAR __ItemsNeeded =

CONCATENATEX(
__ItemsFound,

IF(

[Value2] = BLANK(),
[Value1] & ","
),BLANK()
)

VAR __LENGTH = LEN(__ItemsNeeded)-1

RETURN

IF(
__LENGTH <> -1 ,
LEFT(__ItemsNeeded, __LENGTH)
)

If I create a table visual with Form_OrderID and OrderID (the related field), it looks good:

OrderIDFormOrderID
100100
101101
102102
103103
104

104


 But if I add the measure from above, I get this unexpected result:
Form_OrderIDOrderIDStill Needs
100101Crust,Sauce,Cheese,Topping
100102Crust,Sauce,Cheese,Topping
100103Crust,Sauce,Cheese,Topping
100104Crust,Sauce,Cheese,Topping
101100Crust,Sauce,Cheese,Topping
101102Crust,Sauce,Cheese,Topping
101103Crust,Sauce,Cheese,Topping
101104Crust,Sauce,Cheese,Topping
102100Crust,Sauce,Cheese,Topping
102101Crust,Sauce,Cheese,Topping
102102Sauce,Topping
102103Crust,Sauce,Cheese,Topping
102104Crust,Sauce,Cheese,Topping
103100Crust,Sauce,Cheese,Topping
103101Crust,Sauce,Cheese,Topping
103102Crust,Sauce,Cheese,Topping
103103Crust
103104Crust,Sauce,Cheese,Topping
104100Crust,Sauce,Cheese,Topping
104101Crust,Sauce,Cheese,Topping
104102Crust,Sauce,Cheese,Topping
104103Crust,Sauce,Cheese,Topping
104104Topping

 

I'm not sure what's happening here. I've tried changing the relationship (Power BI detected a bidrectional one-to-one relationship) but to no avail.

 

Can you help me understand what's happening here? This feels like one of those "DAX requires a different way of thinking" conceptual things, but I don't actually know why things are behaving the way they are.

 

Thank you so much,

-Zaiem

 

 

 

 

  • firstly unpiovt your tables as this

     

    and this

    then create a measure like this

    Still Needs = IF(SELECTEDVALUE(PizzaOrderForm[Form_OrderID]),CONCATENATEX(FILTER('PizzaOrderForm','PizzaOrderForm'[Form_OrderID] IN VALUES(Pizza[OrderID])&&NOT('PizzaOrderForm'[Attributes] IN VALUES('Pizza'[Attributes]))),'PizzaOrderForm'[Items],","))

    then create a table visual and put the Form_OrderID, OrderID and the measure in the values area, like this

     

4 Replies

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Community Champion

    firstly unpiovt your tables as this

     

    and this

    then create a measure like this

    Still Needs = IF(SELECTEDVALUE(PizzaOrderForm[Form_OrderID]),CONCATENATEX(FILTER('PizzaOrderForm','PizzaOrderForm'[Form_OrderID] IN VALUES(Pizza[OrderID])&&NOT('PizzaOrderForm'[Attributes] IN VALUES('Pizza'[Attributes]))),'PizzaOrderForm'[Items],","))

    then create a table visual and put the Form_OrderID, OrderID and the measure in the values area, like this

     

    • zbeg's avatar
      zbeg
      Frequent Visitor

      wdx223_Daniel thank you so much! That worked, and now I'm able to break it apart and see what I was doing wrong. I appreciate this a lot. Thank you for taking the time to respond.

  • CNENFRNL's avatar
    CNENFRNL
    Community Champion

    zbeg , obviously, data lineage is lost when you use "{ }" to create a new table __ItemsFound.

    • zbeg's avatar
      zbeg
      Frequent Visitor

      Perhaps obvious to you! 🙂

       

      Is this is a flawed approach? Right approach, flawed execution? How would you solve this problem?