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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
JuanOchoa
Frequent Visitor

Active and Inactive relationships creating issues when filtering tables.

I am getting strange results when using two tables connected with an active and an inactive connection.

 

Table 1: Calendar Date

Table 2: Opportunities with three relevant columns "Opportunities[Created Date],  Opportunities[Closed Date], Opportunities[Opportunity Type]

 

JuanOchoa_1-1644447098717.png

 

and the two relationships between them

JuanOchoa_0-1644447063506.png

 

As part of a long calculation I am trying to find the last opportunity created in a certain period (the period will be selected on a visual by the user using Calendar[Date]).

 

My code:

 

VAR MaxDate =
      CALCULATE (
          MIN ( MAX ( Opportunities[Created Date] ), TODAY () ),      // To avoid errors in case there are created dates after today
         USERELATIONSHIP('Calendar'[Date], Opportunities[Created Date])
      )

VAR MinDate =
     DATE(2017,04,01)
 
// a table with all opportunities whose created date is between MaxDate and MinDate.
// I use this table in the next variable to filter the Opportunities table when
// calculating the maximum created date.

VAR ActiveOps =          
     FILTER (
         'Opportunities',
         ('Opportunities'[Created Date] <= MaxDate)
         && (Opportunities[Created Date] >=MinDate)
         && (Opportunities[Opportunity Type] = "New Business")
     )
 
// simple filter to get the maximum created date in the selected period.
VAR LastOppUptoMaxDate =
     CALCULATE (
         MAX(Opportunities[Created Date]),
         ActiveOps
     )

RETURN LastOppUptoMaxDate

 

To test: I set up filters on the page for (Calendar[Month] = 4) && (Calendar[Year] = 2018) to simulate the user using a slicer ( I actually have a slicer, I didn't want to complicate this post even further)

 

The results:  on the left what the measure above returns and on the right the content of the Opportunities table.

 

JuanOchoa_2-1644448083894.png

Why does my formula return 4/18 as the maximun date when there are opportunities created up to 4/30?

 

I am almost certain that the issue is the combination of active and inactive relationships between the tables, but I haven't been able to figure out why. It's driving me insane. 

 

Thanks for any advice,

 

Juan

 

 

1 ACCEPTED SOLUTION
JuanOchoa
Frequent Visitor

Solved (Sort of)

 

I surrounded the whole thing with a 

 

Calculate(

     ...

     ...,

     USERELATIONSHIP (Calendar[Date], Opportunities[Created Date])

)

 

It now works, but I think this is ugly and I'd love to understand which part of the original measure was failing.

View solution in original post

3 REPLIES 3
JuanOchoa
Frequent Visitor

Solved (Sort of)

 

I surrounded the whole thing with a 

 

Calculate(

     ...

     ...,

     USERELATIONSHIP (Calendar[Date], Opportunities[Created Date])

)

 

It now works, but I think this is ugly and I'd love to understand which part of the original measure was failing.

parry2k
Super User
Super User

@JuanOchoa what does this variable return, can you put it in the return?

 

VAR MaxDate =
      CALCULATE (
          MIN ( MAX ( Opportunities[Created Date] ), TODAY () ),      // To avoid errors in case there are created dates after today
         USERELATIONSHIP('Calendar'[Date], Opportunities[Created Date])
      )

 

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

With the page filters that I have, it returns 2018/04/30

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.