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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
honeybee84
Frequent Visitor

Need help with the DAX calculation to show amounts based on date selection

Hi All, 

 

Thank you very much for reading my post. Really appreciate your help here, as I've been trying to figure out the solution but am stuck. I'm very new to power BI. 

 

I've attached the sample file, hopefully it is clear enough, but what I'd like to see if the different amounts showing up for forecast depending on the date selection. If a date is selected, the amount should be dynamic to look at raw data and filter from that date, current month or last 3 months. I've tried CALCULATE SUM but it does not give the right number. 

 

Raw data

Cost TypeForecast PeriodProjectReporting PeriodAmount
ForecastJun-24AJul-24100
ForecastJun-24AAug-24120
ForecastJun-24ASep-24130
ForecastJun-24AOct-2450
ForecastJun-24ANov-2470
ForecastJun-24ADec-2480
ForecastJun-24AJan-2590
ForecastJun-24AFeb-2510
ForecastJun-24AMar-2550
ForecastJun-24AApr-2570
ForecastJun-24AMay-2580
ForecastJun-24AJun-2590
ForecastJul-24AJul-24 
ForecastJul-24AAug-24110
ForecastJul-24ASep-2490
ForecastJul-24AOct-2480
ForecastJul-24ANov-2470
ForecastJul-24ADec-2460
ForecastJul-24AJan-25120
ForecastJul-24AFeb-25110
ForecastJul-24AMar-25100
ForecastJul-24AApr-2590
ForecastJul-24AMay-2580
ForecastJul-24AJun-25120
ForecastAug-24AJul-24 
ForecastAug-24AAug-24 
ForecastAug-24ASep-2480
ForecastAug-24AOct-2470
ForecastAug-24ANov-24100
ForecastAug-24ADec-2470
ForecastAug-24AJan-2560
ForecastAug-24AFeb-2550
ForecastAug-24AMar-2570
ForecastAug-24AApr-2580
ForecastAug-24AMay-2590
ForecastAug-24AJun-25100

 

Intended Outcome

sample.PNG

Any guidance is very appreciated.

Thank you. 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @honeybee84 ,

I created a sample pbix file(see the attachment), please check if that is what you want.

Current Month Forecast = 
VAR _rperiod =
    SELECTEDVALUE ( 'Table'[Reporting Period] )
VAR _year =
    YEAR ( _rperiod )
VAR _month =
    MONTH ( _rperiod )
VAR _sdate =
    DATE ( _year, _month, 1 )
VAR _edate1 =
    EOMONTH ( _sdate, -1 )
RETURN
    CALCULATE (
        SUM ( 'Table'[Amount] ),
        FILTER (
            ALL ( 'Table' ),
            YEAR ( 'Table'[Forecast Period] ) = YEAR ( _edate1 )
                && MONTH ( 'Table'[Forecast Period] ) = MONTH ( _edate1 )
                && 'Table'[Reporting Period] = _rperiod
        )
    )
Last 3 Months Forecast = 
VAR _rperiod =
    SELECTEDVALUE ( 'Table'[Reporting Period] )
VAR _year =
    YEAR ( _rperiod )
VAR _month =
    MONTH ( _rperiod )
VAR _sdate =
    DATE ( _year, _month, 1 )
VAR _edate3 =
    EOMONTH ( _sdate, -3 )
RETURN
    CALCULATE (
        SUM ( 'Table'[Amount] ),
        FILTER (
            ALL ( 'Table' ),
            YEAR ( 'Table'[Forecast Period] ) = YEAR ( _edate3 )
                && MONTH ( 'Table'[Forecast Period] ) = MONTH ( _edate3 )
                && 'Table'[Reporting Period] >= _edate3 + 1
                && 'Table'[Reporting Period] <= EOMONTH ( _sdate, 0 )
        )
    )
Last 6 Months Forecast = 
VAR _rperiod =
    SELECTEDVALUE ( 'Table'[Reporting Period] )
VAR _year =
    YEAR ( _rperiod )
VAR _month =
    MONTH ( _rperiod )
VAR _sdate =
    DATE ( _year, _month, 1 )
VAR _edate6 =
    EOMONTH ( _sdate, -6 )
RETURN
    CALCULATE (
        SUM ( 'Table'[Amount] ),
        FILTER (
            ALL ( 'Table' ),
            YEAR ( 'Table'[Forecast Period] ) = YEAR ( _edate6 )
                && MONTH ( 'Table'[Forecast Period] ) = MONTH ( _edate6 )
                && 'Table'[Reporting Period] >= _edate6 + 1
                && 'Table'[Reporting Period] <= EOMONTH ( _sdate, 0 )
        )
    )

vyiruanmsft_0-1739155215428.png

Best Regards

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Hi @honeybee84 ,

I'm not sure if I get the correct calculation logic... When select "Aug-24" on the slicer 'Reporting Period', then

  • Current Month Forecast= Amount which the Forecast Period is "Jul-24" and 'Reporting Period' is "Aug-24" vyiruanmsft_2-1738912127836.png
  • Last 3 Months Forecast = Amount which the Forecast Period is "May-24" and 'Reporting Period' is "Aug-24" vyiruanmsft_1-1738912027470.png
  • Last 6 Months Forecast= Amount which the Forecast Period is "Feb-24" and 'Reporting Period' is "Aug-24" 

Am I right?

Best Regards

Yes what you mentioned in your post is exactly what I'm looking for. How to build this logic in power BI? Thank you so much 👏

sorry I should say 

Forecast last 3 months (current month being Aug-24 based on "reporting period") should be forecast May-24 for Jun-24, Jul-24, and Aug-24 (sum of 3 months). 

 

Forecast for last 6 months (current month Aug-24 based on reporting period) should be forecast done in Feb-24 for Mar-24, Apr-24, May-24, Jun-24, Jul-24 and Aug-24 (sum of 6 months).

Anonymous
Not applicable

Hi @honeybee84 ,

I created a sample pbix file(see the attachment), please check if that is what you want.

Current Month Forecast = 
VAR _rperiod =
    SELECTEDVALUE ( 'Table'[Reporting Period] )
VAR _year =
    YEAR ( _rperiod )
VAR _month =
    MONTH ( _rperiod )
VAR _sdate =
    DATE ( _year, _month, 1 )
VAR _edate1 =
    EOMONTH ( _sdate, -1 )
RETURN
    CALCULATE (
        SUM ( 'Table'[Amount] ),
        FILTER (
            ALL ( 'Table' ),
            YEAR ( 'Table'[Forecast Period] ) = YEAR ( _edate1 )
                && MONTH ( 'Table'[Forecast Period] ) = MONTH ( _edate1 )
                && 'Table'[Reporting Period] = _rperiod
        )
    )
Last 3 Months Forecast = 
VAR _rperiod =
    SELECTEDVALUE ( 'Table'[Reporting Period] )
VAR _year =
    YEAR ( _rperiod )
VAR _month =
    MONTH ( _rperiod )
VAR _sdate =
    DATE ( _year, _month, 1 )
VAR _edate3 =
    EOMONTH ( _sdate, -3 )
RETURN
    CALCULATE (
        SUM ( 'Table'[Amount] ),
        FILTER (
            ALL ( 'Table' ),
            YEAR ( 'Table'[Forecast Period] ) = YEAR ( _edate3 )
                && MONTH ( 'Table'[Forecast Period] ) = MONTH ( _edate3 )
                && 'Table'[Reporting Period] >= _edate3 + 1
                && 'Table'[Reporting Period] <= EOMONTH ( _sdate, 0 )
        )
    )
Last 6 Months Forecast = 
VAR _rperiod =
    SELECTEDVALUE ( 'Table'[Reporting Period] )
VAR _year =
    YEAR ( _rperiod )
VAR _month =
    MONTH ( _rperiod )
VAR _sdate =
    DATE ( _year, _month, 1 )
VAR _edate6 =
    EOMONTH ( _sdate, -6 )
RETURN
    CALCULATE (
        SUM ( 'Table'[Amount] ),
        FILTER (
            ALL ( 'Table' ),
            YEAR ( 'Table'[Forecast Period] ) = YEAR ( _edate6 )
                && MONTH ( 'Table'[Forecast Period] ) = MONTH ( _edate6 )
                && 'Table'[Reporting Period] >= _edate6 + 1
                && 'Table'[Reporting Period] <= EOMONTH ( _sdate, 0 )
        )
    )

vyiruanmsft_0-1739155215428.png

Best Regards

thank you very much, this works perfectly!

rajendraongole1
Super User
Super User

Hi @honeybee84  - Since you want the amounts to be dynamic based on the selected "Reporting Period" and look back at different months (M-1, M-3, M-6), you can achieve this using DAX measures in Power BI.

Current Month Forecast (M-1)

 

Please check the attached pbix.





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

Proud to be a Super User!





Hi @rajendraongole1  thank you so much for helping. Unfortunately I cannot open the pbix file due to my BI version not the latest version (it's a company laptop so I cannot install it freely). 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors