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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
C-Jac
Helper I
Helper I

Subtract two dates from different tables indirectly related

I have 4 tables: 

 

Invoice Calendar

Invoices 

Projects

Complete Calendar

 

They are each related, the Invoice Calendar is related to Invoices throug a calendar ID, the Invoices are related to each Project using a Project ID, and each Project is related to the Complete Calendar through a Calendar ID. 

 

What I need is to make a measure which will show me the difference between the Complete Date and Invoice Date in the two tables, and I need to show it like this in Power BI: 

 

Project   Invoice   Complete Date   Invoice Date   Diff   
1101/01/202102/01/20211
1201/01/202103/01/20212
1301/01/202106/01/20215
2105/01/202108/01/20213

 

I've tried setting variables etc. but I cant make it select the column. And I want the connection to be live, and I don't have access to the data model, so it has to be a measure I can put in. 

3 REPLIES 3
stevedep
Memorable Member
Memorable Member
Anonymous
Not applicable

[Diff] =
var OneProjectVisible = HASONEVALUE( Projects[Project ID])
var OneInvoiceVisible = HASONEVALUE( Invoices[Invoice ID] )
var Result =
    if( OneProjectVisible && OneInvoiceVisible,
        var CompleteDate =
            CALCULATE(
                SELECTEDVALUE( 'Complete Calendar'[Date] ),
                Projects
            )
        var InvoiceDate =
            CALCULATE(
                SELECTEDVALUE( 'Invoice Calendar'[Date] ),
                Invoices
            )
        return
            // Assumption is that all projects and all
            // invoices do have non-blank invoice dates
            // and completion dates. If not, you'll have
            // to adjust this formula to account for cases
            // where this assumption is not true. And, of
            // course, I assume that an invoice can have
            // at most 1 invoice date. Same is true for
            // projects - there's at most only one completion
            // date for each of them.
            InvoiceDate - CompleteDate
    )
return
    Result
amitchandak
Super User
Super User

@C-Jac , you need to do it using a common table/s

Refer this: https://community.powerbi.com/t5/Community-Blog/Decoding-Direct-Query-in-Power-BI-Part-2-Date-Differ...

 

same is true for import mode

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.