Showing results for 
Search instead for 
Did you mean: 
Frequent Visitor

Problem creating a line graph with running sums and a simple projection

This is a follow-up from a previous post I made.

 Firstly I'll leave some example data:




Just in case, dates are D-M-Y. The example data assumes a current date of 25-04-2021. Some dates in the arrival_date column are intentionally blank, since those are due in the future. Those are filled in as the packages arrive.


I also have a date table that's joined by both due and arrival dates.


What I need to achieve is a line graph that has three elements:


1) Running total for package_weight by due_date.
2) Running total for package_weight by arrival_date.
3) A simple projection for total package_weight based on a simple estimate. Something like this: first calculating a "daily weight" for last "interval", ie. last package_weight divided by days between penultimate arrival_date and last arrival_date, and then multiplied by amount of days until a given date, eg. 31-07-2021. That should give a very simple projection for the period from last arrival_date to 31-07-2021.


All of this per client. This is, I need to be able to use a slicer to view the data corresponding to a single client.


An example graph of what I want to achieve here:




In the graph blue is running total of package_weight by due_date, orange is running total of package_weightby arrival_date, and red is the projection.


In the previous post I mentioned I received a suggestion that helped me to make one of the running sums work, but not both at the same time in the same graph.

Here's my code:

Cumm due = CALCULATE(CALCULATE(SUM(Table[package_weight]), USERELATIONSHIP(date[date], table[due_date])), FILTER(ALLSELECTED(table[due_date]), ISONORAFTER(table[due_date], MAX(table[due_date]), DESC)))
And it doesn't work for cumm arrival:
Cumm arrival = CALCULATE(CALCULATE(SUM(Table[package_weight]), USERELATIONSHIP(date[date], table[arrival_date]), FILTER(ALLSELECTED(table[arrival_date]), ISONORAFTER(table[arrival_date], MAX(table[arrival_date]), DESC)))
Here's an example graph with different data but same logic of what I see:


Blue is Cumm due and cyan is Cumm arrival. Only Cumm due seems to work.

This is also using due_date as the graph's x axis (Axis box). When I put arrival_date there, it's reversed, Cumm arrival works and Cumm due doesn't. It's kinda obvious it shouldn't work, as I should use the date[date] instead, but when I do, the graph is empty. I imagine this is due to me not using the dates table in my code.


And I'm also missing the projection, and here apparently the forecast functionality is of no help in this case because the dates are not at regular intervals.

Any help is appreciated, thanks in advance!

Community Support
Community Support

Hi @DusanVH 


I guess the relationship between date[date] and table[arrival_date] is an active relationship in your model, so the code for cumm arrival doesn't work. Please remove the USERELATIONSHIP(date[date], table[arrival_date]) part from the code. USERELATIONSHIP is used to activate an inactive relationship in the code. For active relatioships, you don't need it. 


Another reason is that arrival_date column has blank values for future dates. However, blank values are considered less than other non-blank values, so package_weight on those rows will be calculated incorrectly. We need to filter out blank dates in the code. 


Below are my code

Cumm arrival = CALCULATE(SUM('Table'[package_weight]),FILTER(ALLSELECTED('Date'),NOT(ISBLANK('Date'[Date])) && 'Date'[Date]<=MAX('Date'[Date])))
Cumm due = CALCULATE(SUM('Table'[package_weight]), USERELATIONSHIP('Date'[Date], 'Table'[due_date]), FILTER(ALLSELECTED('Date'[Date]), 'Date'[Date]<=MAX('Date'[Date])))


And you should use 'date'[date] in both measures and on X Axis in the line chart. This will avoid missing any date value. 



For the projection part, do you mean to divide the package_weight on the last arrival_date by days between penultimate arrival_date and last arrival_date? And how to get the ending given date? It's a fixed date or a dynamic date?


Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.

Hi @v-jingzhang , thanks for your suggestion, I'll try what you say, but I think you missed that it's per package. I think yours is adding up all packages, maybe you weren't using a slicer to select a package, I guess that should need no code modification. Also, your graphs are stepped, ideally they should be straight lines between each point.

For the projection part, do you mean to divide the package_weight on the last arrival_date by days between penultimate arrival_date and last arrival_date? And how to get the ending given date? It's a fixed date or a dynamic date?

  1. Yes, that's it. In other words, I want the staright line betweem the penultimate package point and the last one to be projected forwards.

  2. Ideally I'd like the projection to have a point at each of the next due_dates. If that's too difficult, using only the last due_date is fine. If even that is too difficult, something simple like last arrival_date + 3 months will do well enough. The projection should be updated as packages arrive.

    To illustrate this better I'll make some graphs. Again, blue is for due_date, orange is for arrival_date and red is for the projection. For each one assume current date to be one day after the last arrival_date. Also, there is a period_start date in another table that I now realized should be used as the starting "zero" point, which I used here to do the first projection.

    This first one is just after package #1 arrives:

    package_IDclient_IDpackage_weightdue_date arr_daterunning_sum_whtProjectionProj_date
    212015-04-2021 303215-04-2021
    313002-05-2021 604402-05-2021
    414030-06-2021 1008630-06-2021

    Second one is just after package #2 arrives. In this one the projection exceeds the maximum of 100, that's intended:

    package_noclient_IDpackage_weightdue_date arr_daterunning_sum_whtProjectionProj_date
    313002-05-2021 606502-05-2021
    414030-06-2021 10012730-06-2021

    Third one is after package #3 arrives:


    package_noclient_IDpackage_weightdue_date arr_daterunning_sum_whtProjectionProj_date
    414030-06-2021 10021430-06-2021

    To create the projection here I got the values by simply calculating the slope for the line between the last and penultimate arrival dates and multiplying that by the difference in days between the corresponding next date and the period start date. The dates for each value is the corresponding due_date.

    As you can see, the projection "advances" and gets updated each time a package arrives.

Thank you very much for your time, you're of great help.

Edit: added missing columns in the tables

Helpful resources

UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Power BI October Update 2021.jpg

Power BI Release

Click here to read more about the October 2021 Release!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Teds Dev Camp Oct. 2021 768x460.jpg

Power BI Dev Camp - October 28th, 2021

Mark your calendars and join us for our next Power BI Dev Camp!