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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
mxblaise
Regular Visitor

Calculated column from two different tables

Hello,

 

There are several post about this topic but I really don't get the logic.

I have two tables feeded by two different files, so two corresponding tables.

 

OperationsTable :

SerialOperationOperation date
1Injection02/01/2018
1Machining04/01/2018
1Visual control07/01/2018
2Injection03/01/2018
2Machining04/01/2018
2Visual control08/01/2018
3Injection03/01/2018
3Machining04/01/2018
3Visual control10/01/2018

 

NDTTable :

SerialNDT date
107/01/2018
210/01/2018
311/01/2018

 

The link between both serial field

In "visualisations" tab, I am doing a "table", in which I check all the fields.

I would like now to comupte in a new column litteraly : NDT date - Operation date WHERE Operation = "Injection"

 

But i dont even know if I should add a collumn to my "visualisation table", or create a new "data table" in which I can do this query and then call it in my "visualisation table".

 

Thanks a lot!

 

Max

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

I believe that this will work:

 

Column = DATEDIFF([NDT date],MAXX(FILTER(RELATEDTABLE(OperationsTable),[Operation]="Injection"),[Operation date]),DAY)

What this is doing:

 

RELATEDTABLE - brings back all related records from OperationsTable

 

FILTER - Filters the results from RELATEDTABLE to just those whose [Operation] is "Injection"

 

MAXX - Grabs the MAX out of a table, could use any aggregation

 

DATEDIFF takes the difference in days between the two dates



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Community Champion
Community Champion

I believe that this will work:

 

Column = DATEDIFF([NDT date],MAXX(FILTER(RELATEDTABLE(OperationsTable),[Operation]="Injection"),[Operation date]),DAY)

What this is doing:

 

RELATEDTABLE - brings back all related records from OperationsTable

 

FILTER - Filters the results from RELATEDTABLE to just those whose [Operation] is "Injection"

 

MAXX - Grabs the MAX out of a table, could use any aggregation

 

DATEDIFF takes the difference in days between the two dates



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hey,

 

I have similar problem and this solution doesn't work as I am getting and error of too many arguments. I have table A with serial number and pending status on a certain date. Second table B with serial number completed status on a certain date and would like to count how many days have passed between pending and completed status.

 

Thanks a lot in advance.

Found out I was missing some parenthesis. The formula works just fine.

Thanks smoupre!

I undrestand a bit better the logic behind. Do you know a good tutorial about this kind of formulas?

 

Max

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors
Top Kudoed Authors