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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Anonymous
Not applicable

If statement total error

Hi Team,

I am writing a simple measure with if condition

if avg fin < avg current fin then sum of Inv_Inv else running total of Inv_Nation, with the below measure my output are correct but my total is not correct.

Measure : 

Inventory_Result_Calculation_Year =
VAR AvgFISCPER = AVERAGE('src_horizon v_horizon_aggregate'[FISCPER])
VAR AvgCurrentFISCPER = AVERAGE('src_horizon v_horizon_aggregate'[CURRENT_FISCPER])
VAR MaxYear = MAX('src_horizon v_horizon_aggregate'[YEAR])
VAR MaxMonthNumber = MAX('src_horizon v_horizon_aggregate'[Month_Number])
VAR MaxWeek = MAX('src_horizon v_horizon_aggregate'[WEEK])
VAR MaxProductGroup = MAX('src_horizon v_horizon_aggregate'[PRODUCT_GROUP])
RETURN
    IF(
       AvgFISCPER < AvgCurrentFISCPER,
        SUM('src_horizon v_horizon_aggregate'[ACT_INV]),
        CALCULATE(
            SUM('src_horizon v_horizon_aggregate'[INVENTORY_NATIONAL]),
            FILTER(ALLSELECTED('src_horizon v_horizon_aggregate'),
                'src_horizon v_horizon_aggregate'[YEAR] <= MaxYear ),
                ALL('src_horizon v_horizon_aggregate') ) )
 
My expeteced total should be 
  82,20,50,276.81

 

PowerBi OutPut 

Raks_0-1687354398565.png

 

Thanks in advance !

   
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Try like

 

Inventory_Result_Calculation_Year =
VAR AvgFISCPER = AVERAGE('src_horizon v_horizon_aggregate'[FISCPER])
VAR AvgCurrentFISCPER = AVERAGE('src_horizon v_horizon_aggregate'[CURRENT_FISCPER])
VAR MaxYear = MAX('src_horizon v_horizon_aggregate'[YEAR])
VAR MaxMonthNumber = MAX('src_horizon v_horizon_aggregate'[Month_Number])
VAR MaxWeek = MAX('src_horizon v_horizon_aggregate'[WEEK])
VAR MaxProductGroup = MAX('src_horizon v_horizon_aggregate'[PRODUCT_GROUP])
VAR Result =
IF(
AvgFISCPER < AvgCurrentFISCPER,
SUM('src_horizon v_horizon_aggregate'[ACT_INV]),
BLANK()
)
RETURN
CALCULATE(
SUM('src_horizon v_horizon_aggregate'[INVENTORY_NATIONAL]),
FILTER(
ALLSELECTED('src_horizon v_horizon_aggregate'),
'src_horizon v_horizon_aggregate'[YEAR] <= MaxYear
),
ALL('src_horizon v_horizon_aggregate'),
Result
)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , Try like

 

Inventory_Result_Calculation_Year =
VAR AvgFISCPER = AVERAGE('src_horizon v_horizon_aggregate'[FISCPER])
VAR AvgCurrentFISCPER = AVERAGE('src_horizon v_horizon_aggregate'[CURRENT_FISCPER])
VAR MaxYear = MAX('src_horizon v_horizon_aggregate'[YEAR])
VAR MaxMonthNumber = MAX('src_horizon v_horizon_aggregate'[Month_Number])
VAR MaxWeek = MAX('src_horizon v_horizon_aggregate'[WEEK])
VAR MaxProductGroup = MAX('src_horizon v_horizon_aggregate'[PRODUCT_GROUP])
VAR Result =
IF(
AvgFISCPER < AvgCurrentFISCPER,
SUM('src_horizon v_horizon_aggregate'[ACT_INV]),
BLANK()
)
RETURN
CALCULATE(
SUM('src_horizon v_horizon_aggregate'[INVENTORY_NATIONAL]),
FILTER(
ALLSELECTED('src_horizon v_horizon_aggregate'),
'src_horizon v_horizon_aggregate'[YEAR] <= MaxYear
),
ALL('src_horizon v_horizon_aggregate'),
Result
)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi!

Did you fix the problem?

If not, you should consider providing some sample data so that it is easier to debug what may cause problems.

Kind regards


Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

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.