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

Max Date Relative To Job Number

I have 3 Tables:

 

Table 1 - List of Unique Job Numbers

Tabel 2 - List of Job Numbers With Original Planned Date

Table 3 - List of Job Numbers With Current Planned Date (Multiple Entries Per Job Number)

 

Table 1

Job Number
Job 1
Job 2
Job 3

 

 

Table 2

Job NumberOriginal Planned Date
Job 101/01/2020
Job 201/02/2020
Job 301/03/2020

 

 

Table 3

Job NumberCurrent Planned Date
Job 106/01/2020
Job 107/01/2020
Job 202/02/2020
Job 204/02/2020
Job 208/02/2020
Job 301/03/2020
Job 308/03/2020

 

What I need to end up with is a new table with the following Job Number, Original Planned Date, the latest Current Planned Date, and a column showing slip:

 

Table 4

Job NumberOriginal Planned DateCurrent Planned DateSlip
Job 101/01/202007/01/20206
Job 201/02/202008/02/20207
Job 301/03/202008/03/20207

 

Any help that people can give will be greatly appreciated.

6 REPLIES 6
v-lili6-msft
Community Support
Community Support

hi  @Anonymous 

If you have created the relationship among these tables by [Job number] column?

https://docs.microsoft.com/en-us/power-bi/desktop-create-and-manage-relationships

If yese, you could use this formula to create a new table:

Table 4 = 
SUMMARIZE (
    'Table 1',
    'Table 1'[Job Number],
    "Original Planned Date", CALCULATE ( MAX ( 'Table 2'[Original Planned Date] ) ),
    "Current Planned Date", CALCULATE ( MAX ( 'Table 3'[Current Planned Date] ) ),
    "Slip", DATEDIFF (
        CALCULATE ( MAX ( 'Table 2'[Original Planned Date] ) ),
        CALCULATE ( MAX ( 'Table 3'[Current Planned Date] ) ),
        DAY
    )
)

If no, you could use this formula to create a new table

Table 5 = 
SUMMARIZE (
    'Table 1',
    'Table 1'[Job Number],
    "Original Planned Date", CALCULATE (
        MAX ( 'Table 2'[Original Planned Date] ),
        FILTER ( 'Table 2', 'Table 2'[Job Number] = 'Table 1'[Job Number] )
    ),
    "Current Planned Date", CALCULATE (
        MAX ( 'Table 3'[Current Planned Date] ),
        FILTER ( 'Table 3', 'Table 3'[Job Number] = 'Table 1'[Job Number] )
    ),
    "Slip", DATEDIFF (
        CALCULATE (
            MAX ( 'Table 2'[Original Planned Date] ),
            FILTER ( 'Table 2', 'Table 2'[Job Number] = 'Table 1'[Job Number] )
        ),
        CALCULATE (
            MAX ( 'Table 3'[Current Planned Date] ),
            FILTER ( 'Table 3', 'Table 3'[Job Number] = 'Table 1'[Job Number] )
        ),
        DAY
    )
)

 

and here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thanks for your reply, I have tried the first example you provided which is nearly what I want but doesn't give quite the right result.

 

In "Table 4" the "Current Planned Date" column retruns the same vale for every job number rather than the max date relative to that job.

 

Do you know how I could change this?

hi  @Anonymous 

Do you create a relationship between table1 and table3 by job number column as below?

10.JPG

 

and also try this formula:

Table 6 = 
SUMMARIZE (
    'Table 1',
    'Table 1'[Job Number],
    "Original Planned Date", MAXX(RELATEDTABLE('Table 2'),[Original Planned Date]),
    "Current Planned Date", MAXX(RELATEDTABLE('Table 3'),[Current Planned Date]),
    "Slip", DATEDIFF (
        MAXX(RELATEDTABLE('Table 2'),[Original Planned Date]),
        MAXX(RELATEDTABLE('Table 3'),[Current Planned Date]),
        DAY
    )
)

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
Super User
Super User

@Anonymous ,Assuming table 1 is Job master. try like

Table 4 =
summarize(Table1, table[job],table2[Original Planned Date], "Current Planned Date",max(Table3[Current Planned Date]),"Slip",
datediff(min(Table3[Current Planned Date]),max(Table3[Current Planned Date]),day))

 

Greg_Deckler
Super User
Super User

This will get you the MAX Current Planned Date: https://community.powerbi.com/t5/Quick-Measures-Gallery/Lookup-Min-Max/td-p/985814


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Greg,

 

Thanks for your help, sorry to be a pain but with my limted knowledge i'm not sure to to impliment this to get the final result i'm after.

 

Could you explain a bit futher or show how it would be applied relative to the examples tables I gave please.

 

Best Regards


Alex

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.