Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Saloni_Gupta
Helper I
Helper I

DAX relationship filter not working

Hi All,
I have data model like this:

Saloni_Gupta_1-1709829808963.png

 

I want to create a calculated column "JP1 or JP2" which would return the values "JP1" or "JP2" based on Job Info table. Lets say, I select Partner Name = Gilbert in my report, my calculation would first look for Gilbert's PartnerId in Partner Info Table and then check if this value is in column "JobPartner1Id" or "JobPartner2Id" for the condition that Relationship = "Managed".
I tried this dax = 

JP1 or JP2 =
var SelectedPartnerId = CALCULATE(MAX('Partner Info'[WorkerId]),'Partner Info'[Preferred Full Name] = SELECTEDVALUE('Partner Info'[Preferred Full Name]))
var ManagedRelJP1 = CALCULATE(MIN('Job Info'[JobPartner1WorkdayId])        
,USERELATIONSHIP('Job Hour Details'[MonthJobJoinKey], 'Partner-Job Relationship'[MonthJobJoinKey]),
USERELATIONSHIP('Job Hour Details'[Job Id], 'Job Info'[Job Id]),
FILTER('Partner-Job Relationship', 'Partner-Job Relationship'[Relationship] = "Managed"))
 
var ManagedRelJP2 = CALCULATE(MIN('Job Info'[JobPartner2WorkdayId])
,USERELATIONSHIP('Job Hour Details'[MonthJobJoinKey], 'Partner-Job Relationship'[MonthJobJoinKey]),
USERELATIONSHIP('Job Hour Details'[Job Id], 'Job Info'[Job Id]),
FILTER('Partner-Job Relationship', 'Partner-Job Relationship'[Relationship] = "Managed"))
 
RETURN  
IF(SelectedPartnerId = ManagedRelJP1 ,"JP1",IF(SelectedPartnerId = ManagedRelJP2,"JP2"))

but the issue is this gives me result for all Relationship (including Booked and PC) and not just for Managed.
Can you help resolve this.

Thanks in Advance!
1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @Saloni_Gupta ,

 

Here are the steps you can follow:

1. Create measure.

Flag =
var _select=SELECTEDVALUE('Partner Info'[Parner Name])
var _selectID=MAXX(FILTER(ALL('Partner Info'),'Partner Info'[Parner Name]=_select),[PartnerId])
return
IF(
    MAX('PartnerJob Relationship'[Partner Id])=_selectID&&MAX('PartnerJob Relationship'[Relationship])="Managed",1,0)
JP1 or JP2 =
var _column1=SELECTCOLUMNS('Job Info',"1ID",'Job Info'[JobPartner1Id])
var _column2=SELECTCOLUMNS('Job Info',"2ID",'Job Info'[JobPartner2Id])
return
IF(
    MAX('PartnerJob Relationship'[Partner Id]) in _column1 ,"JP1",
    IF(
        MAX('PartnerJob Relationship'[Partner Id]) in _column2,"JP2",BLANK()))

2. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_0-1709865611386.png

3. Result:

vyangliumsft_1-1709865611389.png

 

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Hi  @Saloni_Gupta ,

 

Here are the steps you can follow:

1. Create measure.

Flag =
var _select=SELECTEDVALUE('Partner Info'[Parner Name])
var _selectID=MAXX(FILTER(ALL('Partner Info'),'Partner Info'[Parner Name]=_select),[PartnerId])
return
IF(
    MAX('PartnerJob Relationship'[Partner Id])=_selectID&&MAX('PartnerJob Relationship'[Relationship])="Managed",1,0)
JP1 or JP2 =
var _column1=SELECTCOLUMNS('Job Info',"1ID",'Job Info'[JobPartner1Id])
var _column2=SELECTCOLUMNS('Job Info',"2ID",'Job Info'[JobPartner2Id])
return
IF(
    MAX('PartnerJob Relationship'[Partner Id]) in _column1 ,"JP1",
    IF(
        MAX('PartnerJob Relationship'[Partner Id]) in _column2,"JP2",BLANK()))

2. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_0-1709865611386.png

3. Result:

vyangliumsft_1-1709865611389.png

 

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Hi @v-yangliu-msft 
Thanks for your reply, 
I have one question here - what if I dont want to show the column "Relationship" in the final table, I dont think the Flag calculation would display any result. Is there any way to modify the dax to still work when Relationship column is not shown?

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Monthly Update - June 2024

Power BI Carousel June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.