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
Anonymous
Not applicable

Many to Many and Circular Dependency

Hi Folks,

 

Could anyone help a newbie on powerBI?

I have two table, the first is Call for Technical Assistance and second is Technical Repair.

 

Table: Call for Technical AssistanceTable: Call for Technical Assistance Table: Technical RepairTable: Technical Repair

In the Table: Call for Technical Assistance, I want to add a Column with the First Repair Date after the Call Date.

Like this:

 image.png

 

 

I tried following DAX, but there is some problem with Circular Dependency:

Repair_Date = CALCULATE(
    LOOKUPVALUE(
            'Technical Repair'[Repair_Date]; 
            'Technical Repair'[Serial_Number]; MAX([Serial_Number]);
            'Technical Repair'[Repair_Date]; FIRSTDATE('Technical Repair'[Repair_Date])
    )
)
2 ACCEPTED SOLUTIONS
Ashish_Mathur
Super User
Super User

Hi,

 

This calculated column formula in Table1 works fine

 

=CALCULATE(MIN(Table2[Repair_Date]),FILTER(Table2,Table2[Serial_Number]=EARLIER(Table1[Serial_Number])&&Table2[Repair_Date]>EARLIER(Table1[Call_Date])))

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

Hi,

 

Try this calculated column formula

 

=if(ISBLANK(COUNTROWS(FILTER(Table1,Table1[Serial_Number]=EARLIER(Table1[Serial_Number])&&Table1[Call_Date]>EARLIER(Table1[Call_Date])))),CALCULATE(MIN(Table2[Repair_Date]),FILTER(Table2,Table2[Serial]=EARLIER(Table1[Serial_Number])&&Table2[Repair_Date]>EARLIER(Table1[Call_Date]))),if(CALCULATE(MIN(Table1[Call_Date]),FILTER(Table1,Table1[Serial_Number]=EARLIER(Table1[Serial_Number])&&Table1[Call_Date]>EARLIER(Table1[Call_Date])))-[Call_Date]<=30,BLANK(),CALCULATE(MIN(Table2[Repair_Date]),FILTER(Table2,Table2[Serial]=EARLIER(Table1[Serial_Number])&&Table2[Repair_Date]>EARLIER(Table1[Call_Date])))))

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

10 REPLIES 10
Ashish_Mathur
Super User
Super User

Hi,

 

This calculated column formula in Table1 works fine

 

=CALCULATE(MIN(Table2[Repair_Date]),FILTER(Table2,Table2[Serial_Number]=EARLIER(Table1[Serial_Number])&&Table2[Repair_Date]>EARLIER(Table1[Call_Date])))

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @Ashish_Mathur, Thanks a Lot!
Your calculated column formula works.

 

Taking the opportunity.

In your formula, Is it possible I can insert a conditional, to not return duplicates [Repair_Date] where the last [Call_Date] is smaller than 30 days?

Like the Example below:

image.png

Hi,

 

I do not understand your end result.  For BR2, May 5 and May 7 are only 2 days apart.  So why should there be a repair date for May 7?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @Ashish_Mathur,

Thank you for your interest in helping me.

 

In my example,

BR2 had 2 Call_Date in less than 30 days, so I need to ignore the first date in less than 30 days (May 5).

 

The same applies for BR0, that has 3 Call_Dates in less than 30 days.

I need to ignore the first and second date (July 6 and 8), because the last date (July 10) is closest to the date of Repair_Date.

 

 

Hi,

 

The example that you have shown in the picture is different from the one you shared initially.  Paste the two datasets here where in a format that i can paste them in Excel.  Ensure that the dataset that you share now has the duplicate problem that you have shown in your latest post.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi,

 

Yes, I added more lines in the last example.

 

The two table below has the duplicate problem that I shown in my latest post.

 

 Table Call for Technical Assistance

Call_DateSerial_Number
2018-01-01BR1
2018-01-02BR2
2018-01-03BR4
2018-01-04BR0
2018-03-05BR1
2018-05-05BR2
2018-07-06BR0
2018-07-08BR0
2018-07-10BR0

 

 Technical Repair

Repair_DateSerial
2018-02-05BR1
2018-02-10BR2
2018-02-10BR0
2018-02-11BR4
2018-04-01BR1
2018-07-01BR2
2018-08-01BR0

Hi,

 

Try this calculated column formula

 

=if(ISBLANK(COUNTROWS(FILTER(Table1,Table1[Serial_Number]=EARLIER(Table1[Serial_Number])&&Table1[Call_Date]>EARLIER(Table1[Call_Date])))),CALCULATE(MIN(Table2[Repair_Date]),FILTER(Table2,Table2[Serial]=EARLIER(Table1[Serial_Number])&&Table2[Repair_Date]>EARLIER(Table1[Call_Date]))),if(CALCULATE(MIN(Table1[Call_Date]),FILTER(Table1,Table1[Serial_Number]=EARLIER(Table1[Serial_Number])&&Table1[Call_Date]>EARLIER(Table1[Call_Date])))-[Call_Date]<=30,BLANK(),CALCULATE(MIN(Table2[Repair_Date]),FILTER(Table2,Table2[Serial]=EARLIER(Table1[Serial_Number])&&Table2[Repair_Date]>EARLIER(Table1[Call_Date])))))

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

@Ashish_Mathur You are awesome!

 

This formula that's exactly what I needed.

 

Thanks for your patience and support.

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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