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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
user_guddu10
Helper I
Helper I

Issues with Matching Dynamic and Static Emissions Calculations in Power BI

Hello Power BI Community,

I am facing a challenge in my Power BI report where the dynamic calculations for a measure, scope-based emissions, do not align with average emissions under certain conditions, specifically when no scopes or all scopes are selected. I expect these conditions to yield identical results in two different line charts, but they do not.

 

Issue Description:

  1. Line Chart Discrepancy: When no scopes or all scopes are selected, the line chart for "Dynamic Scope Emissions" should mirror the chart for "Avg Asset GHG Emissions (CO2e per $’m)," but the results differ.

  2. Table Totals Mismatch: The total values in my data table for "Dynamic Scopes Emissions" do not match those for "Avg Emissions per Revenue (per Sm)", indicating a potential issue in how totals are computed.

     

Current Setup:

 

1. I use a custom table for scope selections called "Scope Options", defined as follows:
Scope Options =

DATATABLE(

"Scope", STRING,

"Selected", BOOLEAN,

{

{"Scope 1", FALSE},

{"Scope 2", FALSE},

{"Scope 3", FALSE}

}

)

2. Dynamic Scopes Emissions Formula: This formula is designed to dynamically sum emissions based on selected scopes and calculate average emissions per million USD of revenue. The formula and its components are intended to adjust based on the slicer's scope selection:

Dynamic Scopes Emissions =

VAR IsScope1 = CONTAINSROW(VALUES('Scope Options'[Scope]), "Scope 1")

VAR IsScope2 = CONTAINSROW(VALUES('Scope Options'[Scope]), "Scope 2")

VAR IsScope3 = CONTAINSROW(VALUES('Scope Options'[Scope]), "Scope 3")

VAR ScopeSum =

SUM(ESG_Assets_Data_Pivot[scope1]) * IsScope1 +

SUM(ESG_Assets_Data_Pivot[scope2]) * IsScope2 +

SUM(ESG_Assets_Data_Pivot[scope3]) * IsScope3

VAR TotalRevenue = SUM(ESG_Assets_Data_Pivot[revenue_usd])

VAR Default = NOT(IsScope1 || IsScope2 || IsScope3) // True if no scopes are selected

RETURN

DIVIDE(

IF(

Default,

SUMX(

VALUES(ESG_Assets_Data_Pivot[company_name]),

SUM(ESG_Assets_Data_Pivot[scope1]) + SUM(ESG_Assets_Data_Pivot[scope2]) + SUM(ESG_Assets_Data_Pivot[scope3])

),

ScopeSum

),

TotalRevenue / 1000000,

BLANK()

)

3. Additional Measure for Context: "Average Emissions Per Revenue (per mil)" is used to provide a high-level view of emissions efficiency per revenue, calculated as:

Average Emissions Per Revenue (per mil) =
AVERAGEX(
VALUES(ESG_Assets_Data_Pivot[company_name]),
DIVIDE(
[Total Emissions],
SUM(ESG_Assets_Data_Pivot[revenue_usd]) / 1000000,
0
)
)

Where "Total Emissions" is calculated as follows, summing emissions from all three scopes if any are greater than 0.1:

Total Emissions =
IF(
SUM(ESG_Assets_Data_Pivot[scope1]) + SUM(ESG_Assets_Data_Pivot[scope2]) + SUM(ESG_Assets_Data_Pivot[scope3]) > 0.1,
SUM(ESG_Assets_Data_Pivot[scope1]) + SUM(ESG_Assets_Data_Pivot[scope2]) + SUM(ESG_Assets_Data_Pivot[scope3]),
BLANK()
)


AssetAvg Emissions per Revenue (using total emissions)Dynamic Scope Emissionsscope 1scope 2scope 3revenueTotal Emissions 
A0.220.220012.97$58,286,725.8612.97 
B292.95292.95122.22129.1331769.37$109,302,981.6432,020.72 
C307.78307.7812061128116905$387,421,494.72119,239 
Total90.85272.56 1328.221257.13148687.34$555,011,202.23151,272.69 

 

Objective:

The "Dynamic Scope Emissions" should accurately reflect the combination of selected scopes and match the "Avg Asset GHG Emissions" when either all scopes or no scopes are selected.

What I've Tried:

  • Verified slicers are correctly linked.

  • Checked individual asset data which appears accurate.

  • Reassessed formulas for any logical or contextual errors.


Request for Assistance:
Could anyone help identify why these discrepancies occur or suggest modifications to ensure the DAX formula works as intended? Insights into correcting these values would be immensely appreciated.

Thank you for your time and help!

1 ACCEPTED SOLUTION
Poojara_D12
Super User
Super User

Hi @user_guddu10 

The discrepancy between "Dynamic Scope Emissions" and "Avg Asset GHG Emissions" arises from differences in how totals are calculated in DAX versus row-level data. To fix this:

  1. Dynamic Scope Emissions Fix: Ensure the measure calculates totals correctly when no scopes or all scopes are selected. Update it to handle "no scope selected" with a default sum of all scopes.

 

Dynamic Scopes Emissions =
VAR Default = NOT (CONTAINSROW(VALUES('Scope Options'[Scope]), "Scope 1") ||
                   CONTAINSROW(VALUES('Scope Options'[Scope]), "Scope 2") ||
                   CONTAINSROW(VALUES('Scope Options'[Scope]), "Scope 3"))
VAR ScopeSum = 
    SUM(ESG_Assets_Data_Pivot[scope1]) * IsScope1 +
    SUM(ESG_Assets_Data_Pivot[scope2]) * IsScope2 +
    SUM(ESG_Assets_Data_Pivot[scope3]) * IsScope3
RETURN
    DIVIDE(IF(Default, TotalAllScopes, ScopeSum), TotalRevenue / 1_000_000, BLANK())

 

  • Average Emissions Per Revenue Fix: Ensure consistent totals by aggregating row-level values.

 

Average Emissions Per Revenue (per mil) =
AVERAGEX(VALUES(ESG_Assets_Data_Pivot[company_name]), [Total Emissions] / RevenuePerMil)
​

 

  • Debug Totals: Use a debugging measure to check aggregated totals against individual rows.

 

Debug_Total_Emissions = SUMX(VALUES(ESG_Assets_Data_Pivot[company_name]), RowEmissions)
​

 

    1. Validate in a Matrix: Test scenarios with all/no scopes selected to ensure calculations align.

      By correcting total-level aggregation and validating slicer interactions, both measures will align across visuals and totals.

     

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Poojara
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS 

 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos"

Kind Regards,
Poojara - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS

View solution in original post

4 REPLIES 4
v-huijiey-msft
Community Support
Community Support

Hi @user_guddu10 ,

 

Thank you for your interest in this case.

 

My following up is just to ask if the problem has been solved?

 

If so, can you accept the correct answer as a solution or share your solution to help other members find it faster?

 

Thank you very much for your cooperation!

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

Poojara_D12
Super User
Super User

Hi @user_guddu10 

The discrepancy between "Dynamic Scope Emissions" and "Avg Asset GHG Emissions" arises from differences in how totals are calculated in DAX versus row-level data. To fix this:

  1. Dynamic Scope Emissions Fix: Ensure the measure calculates totals correctly when no scopes or all scopes are selected. Update it to handle "no scope selected" with a default sum of all scopes.

 

Dynamic Scopes Emissions =
VAR Default = NOT (CONTAINSROW(VALUES('Scope Options'[Scope]), "Scope 1") ||
                   CONTAINSROW(VALUES('Scope Options'[Scope]), "Scope 2") ||
                   CONTAINSROW(VALUES('Scope Options'[Scope]), "Scope 3"))
VAR ScopeSum = 
    SUM(ESG_Assets_Data_Pivot[scope1]) * IsScope1 +
    SUM(ESG_Assets_Data_Pivot[scope2]) * IsScope2 +
    SUM(ESG_Assets_Data_Pivot[scope3]) * IsScope3
RETURN
    DIVIDE(IF(Default, TotalAllScopes, ScopeSum), TotalRevenue / 1_000_000, BLANK())

 

  • Average Emissions Per Revenue Fix: Ensure consistent totals by aggregating row-level values.

 

Average Emissions Per Revenue (per mil) =
AVERAGEX(VALUES(ESG_Assets_Data_Pivot[company_name]), [Total Emissions] / RevenuePerMil)
​

 

  • Debug Totals: Use a debugging measure to check aggregated totals against individual rows.

 

Debug_Total_Emissions = SUMX(VALUES(ESG_Assets_Data_Pivot[company_name]), RowEmissions)
​

 

    1. Validate in a Matrix: Test scenarios with all/no scopes selected to ensure calculations align.

      By correcting total-level aggregation and validating slicer interactions, both measures will align across visuals and totals.

     

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Poojara
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS 

 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos"

Kind Regards,
Poojara - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS
user_guddu10
Helper I
Helper I

Hi John,

I really appreciate your time. I applied the changes you suggested but they did not give a favourable outcome.

- There was no change in Dynamic Scopes Emissions. It is still displaying the same total on the table and line chart.

- Average emissions per revenue was showing valid data before but with the new formula the line chart shows inaccurate data when I try to validate the line chart with a data in a table.

1. Line chaft with original DAX measures:

user_guddu10_1-1736468766340.png

 



2. Line chart after changes:

user_guddu10_0-1736468649973.png

 

3.This table is showing the count of assets (known as company_name) per year. 

 

user_guddu10_2-1736468912832.png

 


Note: The dynamic scope emissions chart should show the same data when all 3 scopes are selected as the chart above. 

johnt75
Super User
Super User

When using an iterator you need to force context transition by either calling CALCULATE or by using a measure, in which case CALCULATE is implicitly called.

Try

Dynamic Scopes Emissions =
VAR IsScope1 =
    CONTAINSROW ( VALUES ( 'Scope Options'[Scope] ), "Scope 1" )
VAR IsScope2 =
    CONTAINSROW ( VALUES ( 'Scope Options'[Scope] ), "Scope 2" )
VAR IsScope3 =
    CONTAINSROW ( VALUES ( 'Scope Options'[Scope] ), "Scope 3" )
VAR ScopeSum =
    SUM ( ESG_Assets_Data_Pivot[scope1] ) * IsScope1
        + SUM ( ESG_Assets_Data_Pivot[scope2] ) * IsScope2
        + SUM ( ESG_Assets_Data_Pivot[scope3] ) * IsScope3
VAR TotalRevenue =
    SUM ( ESG_Assets_Data_Pivot[revenue_usd] )
VAR Default = NOT ( IsScope1 || IsScope2
    || IsScope3 ) // True if no scopes are selected
RETURN
    DIVIDE (
        IF (
            Default,
            SUMX (
                VALUES ( ESG_Assets_Data_Pivot[company_name] ),
                CALCULATE (
                    SUM ( ESG_Assets_Data_Pivot[scope1] ) + SUM ( ESG_Assets_Data_Pivot[scope2] )
                        + SUM ( ESG_Assets_Data_Pivot[scope3] )
                )
            ),
            ScopeSum
        ),
        TotalRevenue / 1000000,
        BLANK ()
    )

Average Emissions Per Revenue (per mil) =
AVERAGEX (
    VALUES ( ESG_Assets_Data_Pivot[company_name] ),
    DIVIDE (
        [Total Emissions],
        CALCULATE ( SUM ( ESG_Assets_Data_Pivot[revenue_usd] ) ) / 1000000,
        0
    )
)

Your total measure would be more efficient using variables

Total Emissions =
VAR Scope1 =
    SUM ( ESG_Assets_Data_Pivot[scope1] )
VAR Scope2 =
    SUM ( ESG_Assets_Data_Pivot[scope2] )
VAR Scope3 =
    SUM ( ESG_Assets_Data_Pivot[scope3] )
VAR Result =
    IF ( Scope1 + Scope2 + Scope3 > 0.1, Scope1 + Scope2 + Scope3, BLANK () )
RETURN
    Result

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 FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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