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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
abaulo
Frequent Visitor

Calculate running backlog based on two fact tables

Hello everyone!
I'm still getting my bearings with DAX and Data Modeling, so I'm unsure how to phrase the question.
I've tried wording it many ways to find an existing solution to no avail. Even if you're input is a link to the appropriate forum post, it would be very much appreciated.

 

I've stripped down the tables for sharing the basic structure of the data.

Here is a link to the file: Sample file

  

 

abaulo_0-1645039955498.png

  

The Template table records trips to the job site to measure/draw the fabrication template. 

The Install table records installation trips to the job site. 

  

I'm trying to find a way to sum the square footage from the Template table for Jobs that: 

  1. Have a Template date <= date context
  2. Do not have an Install date <= date context

I'm calling this the "Backlog" of footage that needs to be installed.

 

 

 

Backlog =
VAR MaxDate =
    //Get the latest date from the Week of Year context
    MAX ( 'Calendar'[Date] )
VAR TemplatedJobs =
    //Get JobIDs of Templated Jobs thus far
    CALCULATETABLE (
        SUMMARIZE (
            Template,
            Job_Info[JobID]
        ),
        Template[Template Date] <= MaxDate
    )
VAR InstalledJobs =
    //Get JobIDs of Installed Jobs thus far
    CALCULATETABLE (
        SUMMARIZE (
            Install,
            Job_Info[JobID]
        ),
        Install[Install Date] <= MaxDate
    )
VAR TemplatedNotInstalled =
    //Get JobIDs of jobs that have been Templated but not Installed
    EXCEPT (
        TemplatedJobs,
        InstalledJobs
    )
RETURN
    //Sum the Sqft of those jobs
    CALCULATE (
        [Templated Footage], //= SUM(Template[SqFt])
        TemplatedNotInstalled
    )

 

 

 

I'm expecting to see the Backlog footage change from week to week as installs happen, but so far it is just matching the Templated Footage measure:

abaulo_0-1645042215357.png

 

Though the "Total" seems to be correct...so that's a start.

 

How can I get the individual weeks to show the correct Backlog?

 

Thanks in advance for any assistance you can provide!

1 ACCEPTED SOLUTION
abaulo
Frequent Visitor

@Greg_Deckler , thanks for the tips!

I used CONCATENATEX to figure out what was happening in each CALCULATETABLE. I eventually got the following to work, though I'm still not entirely sure why I have to include ALL in each CALCULATETABLE, which leads me to believe there's probably a more elegant solution.

Backlog = 

var MaxDate = //Get the latest date from the Week of Year context
    MAX('Calendar'[Date]) 

var TemplatedJobs = //Get JobIDs of Templated Jobs thus far
    CALCULATETABLE(
        SUMMARIZE(
            Template,
            Job_Info[JobID]
        ),
        Template[Template Date] <= MaxDate, 
        ALL(Template)
    )

var InstalledJobs = //Get JobIDs of Installed Jobs thus far
    CALCULATETABLE(
        SUMMARIZE(
            Install,
            Job_Info[JobID]
        ),
        Install[Install Date] <= MaxDate,
        ALL(Install)
    )

var Backlog = //Get JobIDs of jobs that have been Templated but not Installed
    EXCEPT(
        TemplatedJobs,
        InstalledJobs
    )

Return  //Sum the Sqft of those jobs
    CALCULATE(
        [Templated Footage], //= SUM(Template[SqFt])
        Template[JobID] IN Backlog,
        ALL(Template)
    )



View solution in original post

2 REPLIES 2
abaulo
Frequent Visitor

@Greg_Deckler , thanks for the tips!

I used CONCATENATEX to figure out what was happening in each CALCULATETABLE. I eventually got the following to work, though I'm still not entirely sure why I have to include ALL in each CALCULATETABLE, which leads me to believe there's probably a more elegant solution.

Backlog = 

var MaxDate = //Get the latest date from the Week of Year context
    MAX('Calendar'[Date]) 

var TemplatedJobs = //Get JobIDs of Templated Jobs thus far
    CALCULATETABLE(
        SUMMARIZE(
            Template,
            Job_Info[JobID]
        ),
        Template[Template Date] <= MaxDate, 
        ALL(Template)
    )

var InstalledJobs = //Get JobIDs of Installed Jobs thus far
    CALCULATETABLE(
        SUMMARIZE(
            Install,
            Job_Info[JobID]
        ),
        Install[Install Date] <= MaxDate,
        ALL(Install)
    )

var Backlog = //Get JobIDs of jobs that have been Templated but not Installed
    EXCEPT(
        TemplatedJobs,
        InstalledJobs
    )

Return  //Sum the Sqft of those jobs
    CALCULATE(
        [Templated Footage], //= SUM(Template[SqFt])
        Template[JobID] IN Backlog,
        ALL(Template)
    )



Greg_Deckler
Super User
Super User

@abaulo I don't see anything obviously wrong with the calculation. I will have to pull down the file and take a closer look. What you can do is to change your RETURN statement to make sure the individual parts of the formula are correct, like returning MaxDate. You can also use CONCATENATEX against your table variables to "look inside" those tables and see what they contain and if they contain the correct things.



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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