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
GJA
Helper II
Helper II

Relationship and DAX formulas returns nothing

Hi,

I have a relationship which affects the results of my Dax Formulas. 

 

In the table "Equipment Header" I have informations about Equipments related to some days (not every day). I created a table "PNT_Control Equipment" in which I have one row per Equipment and day for each Equipment and each day. Both are linked with a bidirectionnal relationship on a key composed by date and Equipment ID.

 

When I create a column with DAX in "PNT_Control Equipment" in order to get the name of the of the Equipment (in the other table) for exemple, it returns nothing for the dates which doesn't exists in "Equipment Header".

 

I would like a result for each row. I see that if I delete the relationship it works but I need this relationship.

 

I have some troubles because on the other hand I have exactly the same relationship between other tables and it works.

 

I tried this simple formula for example : 

LASTNONBLANK('Equipment Header'[cle_pnt_control_equipment],1) Thanks in advance for your help

 

2020-07-09_11-08-55.jpg

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

Hi GJA,

 

My solution consists of three calculated columns in table PNT Control Equipment. The field Composite Key is composed of Date and Equipment ID. The concept of the solution is if there is no match in Equipment Header, get the most recent Date in Equipment Header for the current Equipment ID, create a new Composite Key with this Date, and then lookup the name of the equipment based on this new Composite Key.

 

DataInsights_0-1594312009727.png

DataInsights_1-1594312061945.png

DataInsights_2-1594312105809.png

 

DAX below so you can copy/paste:

 

Equipment Header Most Recent Date =
--see if there is a match on Date and Equipment ID
VAR EqHdrCompKey =
LOOKUPVALUE (
'Equipment Header'[Date],
'Equipment Header'[Composite Key], 'PNT Control Equipment'[Composite Key]
)
--if no match, get the most recent date for which there is a match on Equipment ID
VAR EqHdrTable =
FILTER (
'Equipment Header',
'PNT Control Equipment'[Equipment ID] = 'Equipment Header'[Equipment ID]
)
VAR MinDate =
MINX ( EqHdrTable, 'Equipment Header'[Date] )
VAR Result =
IF ( ISBLANK ( EqHdrCompKey ), MinDate, EqHdrCompKey )
RETURN
Result

 

Composite Key Most Recent Date = 'PNT Control Equipment'[Equipment Header Most Recent Date] & 'PNT Control Equipment'[Equipment ID]

 

Equipment Name =
LOOKUPVALUE (
'Equipment Header'[Equipment Name],
'Equipment Header'[Composite Key], 'PNT Control Equipment'[Composite Key Most Recent Date]
)

 

Hope this resolves the issue.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
DataInsights
Super User
Super User

Hi GJA,

 

My solution consists of three calculated columns in table PNT Control Equipment. The field Composite Key is composed of Date and Equipment ID. The concept of the solution is if there is no match in Equipment Header, get the most recent Date in Equipment Header for the current Equipment ID, create a new Composite Key with this Date, and then lookup the name of the equipment based on this new Composite Key.

 

DataInsights_0-1594312009727.png

DataInsights_1-1594312061945.png

DataInsights_2-1594312105809.png

 

DAX below so you can copy/paste:

 

Equipment Header Most Recent Date =
--see if there is a match on Date and Equipment ID
VAR EqHdrCompKey =
LOOKUPVALUE (
'Equipment Header'[Date],
'Equipment Header'[Composite Key], 'PNT Control Equipment'[Composite Key]
)
--if no match, get the most recent date for which there is a match on Equipment ID
VAR EqHdrTable =
FILTER (
'Equipment Header',
'PNT Control Equipment'[Equipment ID] = 'Equipment Header'[Equipment ID]
)
VAR MinDate =
MINX ( EqHdrTable, 'Equipment Header'[Date] )
VAR Result =
IF ( ISBLANK ( EqHdrCompKey ), MinDate, EqHdrCompKey )
RETURN
Result

 

Composite Key Most Recent Date = 'PNT Control Equipment'[Equipment Header Most Recent Date] & 'PNT Control Equipment'[Equipment ID]

 

Equipment Name =
LOOKUPVALUE (
'Equipment Header'[Equipment Name],
'Equipment Header'[Composite Key], 'PNT Control Equipment'[Composite Key Most Recent Date]
)

 

Hope this resolves the issue.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you it solved my 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.