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
ValeriaBreve
Post Patron
Post Patron

running total from a given date

Hello,

I am trying to compute a running total for a forecast per year, but not from the beginning of the year, just from the first date when there are no more actuals.

It is shown in a table per month/year.

 

I have come up with the formula below, however I cannot understand why my forecast is always summed from the beginning of the year (Jan 1st) - all dates are working correctly, LastDateWithSpending is giving me the right date, DATESBETWEEN is correctly starting from the LastDateWithSpending+1...

[Forecast] measure is just the sum of the Forecast column.

 

How do I force DAX to ignore the forecast from Jan 1st until the LastDateWithSpending and only start the cumulative sum from LastDateWithSpending+1 day?

 

WIth the formula below, I get correctly 0 for all months before the month of LastDateWithSpending, however the first non blank month is the sum of all forecast for the previous months since beginning of the year.

 

Thanks!

Kind regards

Valeria

 

Remaining Cumulative Forecast =
VAR LastDateWithSpending =
    CALCULATE (
        MAX ( 'Actuals'[Date] ),
        ALL ( 'Actuals') ,
        FILTER('Actuals',
            'Actuals'[Spending USH$]>0)
    )
 VAR LastVisibleDate = MAX(DateTable[Date])

VAR Result =
If(
    LastVisibleDate>LastDateWithSpending,
        CALCULATE(
        [Forecast],
       KEEPFILTERS(DateTable[Date]>LastDateWithSpending),
     DATESBETWEEN(DateTable[Date],LastDateWithSpending+1,LastVisibleDate)),
     0)
   
RETURN
Result

 

1 ACCEPTED SOLUTION
some_bih
Super User
Super User

Hi @ValeriaBreve  one of possible implementation is following:

1. In Date table insert column with code 

IF([Date]>=EOMONTH(TODAY(),-2)
            , TRUE,FALSE)
2. Measure for forecast is simple sum, 
M_forecast = sum(Sheet10[Forecast])
Adjust Sheet10 to your table name
3. Measure for Expected:
M_for_Expected =
    CALCULATE([M_forecast],
    'Date'[EOM and future]=TRUE
    )
4. Finally, measure for YTD expected amount
M_Expected_test =
    CALCULATE(
        [M_forecast],
        DATESYTD('Date'[Date]),
        'Date'[EOM and future]=TRUE
    )
End of Month below is column from Date column table
 I hope this help
some_bih_0-1685625858865.png

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






View solution in original post

4 REPLIES 4
some_bih
Super User
Super User

Hi @ValeriaBreve  one of possible implementation is following:

1. In Date table insert column with code 

IF([Date]>=EOMONTH(TODAY(),-2)
            , TRUE,FALSE)
2. Measure for forecast is simple sum, 
M_forecast = sum(Sheet10[Forecast])
Adjust Sheet10 to your table name
3. Measure for Expected:
M_for_Expected =
    CALCULATE([M_forecast],
    'Date'[EOM and future]=TRUE
    )
4. Finally, measure for YTD expected amount
M_Expected_test =
    CALCULATE(
        [M_forecast],
        DATESYTD('Date'[Date]),
        'Date'[EOM and future]=TRUE
    )
End of Month below is column from Date column table
 I hope this help
some_bih_0-1685625858865.png

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Thanks! This works 🙂

I still don't get why my code was not working... well I'll probably get to it when I am finished with the DAX course by Marco Russo and Alberto Ferrari! Give me a few months though - my brain is limited  😂 

Thanks again :-0)

ValeriaBreve
Post Patron
Post Patron

@some_bih Hello, it really looks quite simple...

But I can't figure it out.

I am adding a column with epected result, and another one with what I am getting today with my formula (so what I DON'T want).

And this should be by YEAR (so every following year the running total of the forecast is resetting and starting again from Jan)

Thanks!

Kind regards

Valeria

 

DateActualsForecastExpected ResultWhat I am getting today…
Jan-235667  
Feb-232630  
Mar-233547  
Apr-232629  
May-23 3535208
Jun-23 3772245
Jul-23 63135308
Aug-23 30165338
Sep-23 26191364
Oct-23 39230403
Nov-23 35265438
Dec-23 55320493
some_bih
Super User
Super User

 Hi @ValeriaBreve please provide some sample data and expected output with your solution.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






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