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
Binway
Helper II
Helper II

Current Month Calc, forecast and Pro rate

Hi Folks,

I a financial year starting in April where I need to calculate the current months average for the previous 3 months and forecast to the end of the year, but with the current month showing pro-rata data based on the days left in the month.

The Matrix would look like this:

ValuesAprMayJunJulAugSepOctNovDecJanFebMarTotals
Monthly Sales645.053837.207955.129811.420354.521       3603.330
Avg Prevs 3 mths     612.750707.023707.023707.023707.023707.023707.0234854.888

 

 

I found how to forecast using the DATESYTD with the End of Financial Year, and got the average to work in one of my attempts by dividing by 3 which is fine but can't quite get it all together.  This is the best example I have so far.

 

CALCULATE(
                  CALCULATE(
CALCULATE(CALCULATE(CALCULATE(SUMX(Sales,DIVIDE(Sales[Amount],Sales[Weighting],0)/1000),FILTER(ALL(Sales[Currency]), Sales[Currency]="AUD")),
DATESBETWEEN('Date'[Date],
                       DATEADD ( FIRSTDATE ('Date'[Date] ), -3, MONTH ),
        DATEADD(LASTDATE ('Date'[Date]),-1,MONTH )                                        ))
   ),FILTER('Date', 'Date'[Date]=EOMONTH(TODAY(),0))),DATESYTD('Date'[Date],"31/3")
      ,FILTER('Date', 'Date'[Month #]=MONTH(TODAY())))/'Date'[DaysinCurrentMonth] *'Date'[DaysLeftCurrentMonth]

Appreciate the help.

 

Binway

9 REPLIES 9
v-cherch-msft
Employee
Employee

Hi @Binway

 

Here are some references for you:

 

https://community.powerbi.com/t5/Desktop/Forecasting-future-months-using-previous-months-data-on-a-f...

https://www.sqlbi.com/articles/rolling-12-months-average-in-dax/

 

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Cherie,

Got the Forecast code working.  Seems my Month/Year needs to be a date.

Hopefully can tweak this to suite my needs.

 

FrcstDtaWrks.PNG

 

Hi @Binway

 

It seems you may need a calendar date table. If it is not your case, please share some data sample file. You can upload it to OneDrive or Dropbox and post the link here.

 

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I am getting closer to the required output but can't seem to get the filter for the current month correct to the requirement shown.

FrcstDtReqmnt.PNG

The current results row shows I can get the previous 3 mths average and forecast it to their EOFY with this code:

Current Result = 
CALCULATE(CALCULATE(AVERAGEX( DATESBETWEEN('Date'[Date],
                       DATEADD ( FIRSTDATE ('Date'[Date] ), -3, MONTH ),
        DATEADD(LASTDATE ('Date'[Date]),-1,MONTH ) 
          ) ,
        CALCULATE(SUMX(Sales,DIVIDE(Sales[Amount],Sales[Weighting],0))/1000,FILTER(ALL(Sales[Currency]), Sales[Currency]="AUD"))
                                ),FILTER('Date', MONTH('Date'[Date])=MONTH(TODAY()))),DATESYTD('Date'[Date],"31/3"))

But I can't filter it so it is just for the current month pro-rata.

 

Certainly I can filter the monthly sales row to show just the current month so it is not because the data is in a Matrix.

Monthly Sales = CALCULATE(CALCULATE(SUMX(Sales,DIVIDE(Sales[Amount],Sales[Weighting],0)/1000),FILTER(ALL(Sales[Currency]), Sales[Currency]="AUD")),FILTER('Date', MONTH('Date'[Date])=MONTH(TODAY())-1))

FrcstDtaNew.PNG

 

I am thinking I will need an IF statment as well so if it is the current month then formula pro-rata plus another to forecast to EOFY without the pro-rata.

Any thoughts appreciated.

 

I found a more elegant and accurate way to calculate the average for the previous 3 months.

Average_Test = AVERAGEX( DATESBETWEEN('Date'[Date],
                       DATEADD ( FIRSTDATE ('Date'[Date] ), -3, MONTH ),
        DATEADD(LASTDATE ('Date'[Date]),-1,MONTH ) 
          ) ,
        CALCULATE(SUMX(Sales,DIVIDE(Sales[YTD less rebates],Sales[DistnctSesnlDys],0))/1000,FILTER(ALL(Sales[Currency]), Sales[Currency]="AUD"))
                                )

I am now looking to filter and add the pro-rate calcualtion for the current month as well as Forecast the value to the end of the Financial Year using:

 

DATESYTD('Date'[Date],"31/3")

Hi Cherie,

You may get a better view from the PBIX file - hopefully you can see it.

Avg Forecast Rpt

I have broken the calculations down and put them in the matrix along with what would be the final field which presents correctly but the calcualtion is not the average of the previous 3 mths.

 

 

Thanks Binway

Hi Cherie,

Got the Forecast code working.  Seems my Month/Year needs to be a date.

Hopefully can tweak this to suite my needs.

 

FrcstDtaWrks.PNG

 

Thanks Cherie it looked like the code and resutls in the "Forecasting Future Months" link would do the job. Your code looks like this:

Measure =
IF (
    ISBLANK ( SUM ( 'Actual Spend'[Corporate Card Spend] ) ),
    AVERAGEX (
        CALCULATETABLE (
            VALUES ( 'Calendar Dates'[Month/Year] ),
            ALLEXCEPT ( 'Calendar Dates', 'Calendar Dates'[Fiscal Year] )
        ),
        CALCULATE ( SUM ( 'Actual Spend'[Corporate Card Spend] ) )
    )
)

I thouhgt I would start with a simple replication of your code which is not that different:

 

AA1_FrmDskFrm = 
IF (
    ISBLANK (SUM([Amount]) ),
    AVERAGEX (
        CALCULATETABLE (
            VALUES('Date'[Month-year] ),
            ALLEXCEPT ( 'Date','Date'[Financial year])
        ),
        CALCULATE(SUM([Amount]))
    )
)

But the result is not similiar - have I got to do something different in the Date table perhaps.Below is the result. Sorry just started reading Alberto's Definitive Guide to DAX so have bit to learn. results I get

 

FrcstDta.PNG 

 

Regards

Binway

Greg_Deckler
Super User
Super User

See if my Time Intelligence the Hard Way Quick Measure helps: 

 

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.