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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
TanHY
Helper I
Helper I

Power BI Incorrect Total in Pivot Table

Hey Power BI Wizard, 

I have met the total error in my power bi, and I scratched out my head still couldnt solve it. For context: I have a forecast and actual sales dataset for my power bi, and I wish to dynamically calculated the leftover target to achieve in power bi pivot table. 

TanHY_1-1734593019894.png

Here is my dax:

Development =
VAR _MinDateQuarter = CALCULATE(
    MIN('Date'[Date]),
    REMOVEFILTERS('Date'[Month]),
    'Date'[Fiscal Year Quarter Number] = MIN('Date'[Fiscal Year Quarter Number]),
    ALLEXCEPT('Date','Date'[Fiscal Year], 'Date'[Fiscal Year Quarter] )
)

VAR _MaxDateQuarter = CALCULATE(
    MAX('Date'[Date]),
    REMOVEFILTERS('Date'[Month]),
    'Date'[Fiscal Year Quarter Number] = MIN('Date'[Fiscal Year Quarter Number]),
    ALLEXCEPT('Date','Date'[Fiscal Year], 'Date'[Fiscal Year Quarter] )
)

VAR _ActualMaxDate = EOMONTH(TODAY(), -1) -- Return the last date of last month
VAR _ForecastMinDate = EOMONTH(TODAY(), -1) + 1 -- Return the first date of this month

VAR _MonthActualValue =  CALCULATE(SUM(SG_Budget_Forecast_View[Value]))
VAR _TotalActualValue = CALCULATE(SUM(SG_Budget_Forecast_View[Value]), DATESBETWEEN('Date'[Date],_MinDateQuarter,_ActualMaxDate))
VAR _TotalForecastValue = CALCULATE(SUM(Forecast[Value]), DATESBETWEEN('Date'[Date], _MinDateQuarter, _MaxDateQuarter))
VAR _MonthActualCount = CALCULATE(
        COUNT(SG_Budget_Forecast_View[Value]),
        ALLEXCEPT('Date', 'Date'[Fiscal Year], 'Date'[Fiscal Year Quarter]), -- Retains only the fiscal year and quarter filters
        SG_Budget_Forecast_View[NormalDate] < _ActualMaxDate -- Filters rows by date
    )
VAR _MonthForecastCount = CALCULATE(
        COUNT(Forecast[Value]),
        ALLEXCEPT('Date', 'Date'[Fiscal Year], 'Date'[Fiscal Year Quarter]), -- Retains only the fiscal year and quarter filters
        Forecast[NormalDate] >= _ForecastMinDate -- Filters rows by date
    )

VAR _CurrentMaxQuarterDate = SWITCH(
    TRUE(),
    MONTH(_ForecastMinDate) IN {8,11,2,5}, EOMONTH(_ForecastMinDate,2),
    MONTH(_ForecastMinDate) IN {9,12,3,6}, EOMONTH(_ForecastMinDate,1),
    EOMONTH(_ForecastMinDate,0)
)


RETURN
SWITCH(
    TRUE(),
    MAX('Date'[Date]) <= _ActualMaxDate, _MonthActualValue,
    AND(
        MAX('Date'[Date]) >= _ActualMaxDate + 1,
        MAX('Date'[Date]) <= _CurrentMaxQuarterDate
    ), ((_TotalForecastValue - _TotalActualValue) / _MonthForecastCount) ,
    SUMX(Forecast,_TotalForecastValue / _MonthForecastCount)
    )
I know there is something related to iteration row. Hope to get some advices and lets discuss.
2 ACCEPTED SOLUTIONS
danextian
Super User
Super User

Hi @TanHY 

The most likely cuplrit is you conditional formula after  RETURN. MAX ('Date'[Date]) is evaluated differently at each hierarchy level. Try in a new measure:

SUMX (
    SUMMARIZECOLUMNS (
        'table'[Category],
        'table'[Subcategory],
        "@Development", [Development ]
    ),
    [@Development]
)

Change category and subcategory to the actual row columns in your matrix.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

Hi, 

Thanks. its work!!

View solution in original post

3 REPLIES 3
danextian
Super User
Super User

Hi @TanHY 

The most likely cuplrit is you conditional formula after  RETURN. MAX ('Date'[Date]) is evaluated differently at each hierarchy level. Try in a new measure:

SUMX (
    SUMMARIZECOLUMNS (
        'table'[Category],
        'table'[Subcategory],
        "@Development", [Development ]
    ),
    [@Development]
)

Change category and subcategory to the actual row columns in your matrix.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi, 

Thanks. its work!!

Please accept my post as the solution. Thanks!





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.