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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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.










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


Proud to be a Super User!









"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.










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


Proud to be a Super User!









"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!










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


Proud to be a Super User!









"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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.