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

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

 

 

 

 

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

firstly unpiovt your tables as this

wdx223_Daniel_0-1612918443812.png

 

and this

wdx223_Daniel_1-1612918460156.png

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

wdx223_Daniel_2-1612918609076.png

 

View solution in original post

4 REPLIES 4
wdx223_Daniel
Super User
Super User

firstly unpiovt your tables as this

wdx223_Daniel_0-1612918443812.png

 

and this

wdx223_Daniel_1-1612918460156.png

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

wdx223_Daniel_2-1612918609076.png

 

@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
Community Champion
Community Champion

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


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

zbeg
Frequent Visitor

Perhaps obvious to you! 🙂

 

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

 

 

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.

Top Solution Authors