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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
CaveOfWonders
Helper IV
Helper IV

Difference in Days Between 2 Measures Reaching The Same Figure

Dear Community,

 

I can't get my head round something and need your help.

 

I have two measures plotted on a line chart against time:

 

Planned Works Cumulative: (Gives me a cumulative count of rows where the Planned Works column (Date Column) is populated)
Completed Works Cumulative: (Gives me a cumulative count of rows where the Completed Works (Date Column) column is populated)

 

Diff.JPG

The completed works measure calculates completed works up until the end of the last month (200 at the end of June for example).

The Planned works measure is up until the end of the project.

 

I need to dynamicallay work out how many days ahead or behind 'Planned Works' is from the 'Completed Works'. In the current example completed works is 200 at the end of last month (June) and planned works is >= 200 on the 10th July (10 day difference), so the measure needs to display 10 days as the result.

 

Diff2.JPG

Your help is appreciated.

 

 

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @CaveOfWonders ,

 

Try creating this measure:

 

_daysAheadBehind = 
DATEDIFF(
    CALCULATE(
        FIRSTNONBLANKVALUE(aTable[plannedWorks], MAX(aTable[date])),
        FILTER(
            aTable,
            aTable[plannedWorks] >= MAX(aTable[completedWorks])
        )
    ),
    LASTNONBLANKVALUE(aTable[completedWorks], MAX(aTable[date])),
    DAY
)

 

 

This gives me the following output:

caveofwonders.PNG

 

 

I have edited my inital response to more accurately reflect your requirements.

Can the completed works ever exceed the planned works? If so, this needs more work.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

3 REPLIES 3
BA_Pete
Super User
Super User

Hi @CaveOfWonders ,

 

Try creating this measure:

 

_daysAheadBehind = 
DATEDIFF(
    CALCULATE(
        FIRSTNONBLANKVALUE(aTable[plannedWorks], MAX(aTable[date])),
        FILTER(
            aTable,
            aTable[plannedWorks] >= MAX(aTable[completedWorks])
        )
    ),
    LASTNONBLANKVALUE(aTable[completedWorks], MAX(aTable[date])),
    DAY
)

 

 

This gives me the following output:

caveofwonders.PNG

 

 

I have edited my inital response to more accurately reflect your requirements.

Can the completed works ever exceed the planned works? If so, this needs more work.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Hey Pete,

 

Thank you for the quick response.

 

The last non blank value for planned works is towards the end of 2021 and has a value of 1000+. The data table I provided was maybe a little misleading: Here's a slightly more accurate depiction of what's going on; with this in mind, I don't think LASTNONBLANK will work. Also these two columns are measures and not tables, however, if it worked I would have probably created calculated columns to make it work.

 

Sorry, I have just seen your updated response, let me have a look and get back to you; thank you 🙂

 

Diff2.JPG

 

 

 

 

Thanks Pete,

 

It worked 🙂

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors