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
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

 

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