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
sovereignauto
Helper III
Helper III

Min from related table and then between two columns

Morning, 

i have two tables, Table2 has multiple records to Table1

the tables are linked by Ref - so im looking to get the earliest date from table2[date_1] for each row in table1

then i need to get the earliest from table1[date] and table1[the new col]

 

Table 2:

 

Refdate deliverd
12345601/01/2021
12378907/01/2021
12345604/01/2021
12378903/01/2021

 

Table 1:

 

refdate closedfirst date deliverddate actioned 
123456 Returned from above table=first date deliverd or date closed (depending on whats filled out)
12345801/01/2021  
123789 Returned from above table 
12358701/01/2021  



hope this makes sense and thank you! 

1 ACCEPTED SOLUTION
v-robertq-msft
Community Support
Community Support

Hi, @sovereignauto 

According to your description and sample data, I can clearly understand your requirement, I think you can achieve this using DAX to create two columns, you can follow my steps:

Create two calculated columns like this:

v-robertq-msft_0-1619082674978.png

 

first date delivered =

MINX(FILTER(ALL('Table 2'),[ref]=EARLIER([ref])),[date deliverd])
date actioned =

SWITCH(

    TRUE(),

    [date closed]=BLANK(),[first date delivered],

    [first date delivered]=BLANK(),[date closed],

    IF([date closed]<=[first date delivered],[date closed],[first date delivered]))

 

And you can get what you want, like this:

v-robertq-msft_1-1619082674982.png

 

You can download my test pbix file below

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

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

3 REPLIES 3
v-robertq-msft
Community Support
Community Support

Hi, @sovereignauto 

According to your description and sample data, I can clearly understand your requirement, I think you can achieve this using DAX to create two columns, you can follow my steps:

Create two calculated columns like this:

v-robertq-msft_0-1619082674978.png

 

first date delivered =

MINX(FILTER(ALL('Table 2'),[ref]=EARLIER([ref])),[date deliverd])
date actioned =

SWITCH(

    TRUE(),

    [date closed]=BLANK(),[first date delivered],

    [first date delivered]=BLANK(),[date closed],

    IF([date closed]<=[first date delivered],[date closed],[first date delivered]))

 

And you can get what you want, like this:

v-robertq-msft_1-1619082674982.png

 

You can download my test pbix file below

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

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

webportal
Impactful Individual
Impactful Individual

Not very sure I understood your question.

If you need a calculated column on Table2 to get the earliest date from a related Table1, you could try:

 

Column = MINX(RELATEDTABLE(Table2), 'Table2'[Date])

I have updated my post with a couple of tables

so i need the earliest date from the records with the same ref but then i also need to add a column to get "actioned date" from the new column and an exsisting column so think i need it in power query rather than DAX?

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.