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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Email60
Regular Visitor

SUMX inexplicably produces different results in two measures

Dear all

 

I am experiencing that a piece of DAX-code does what it's supposed to in one measure, but if the same piece of code is inserted in another (slightly more complicatied) measure it does not.

 

I am working on a live connection to my company's cube.

 

I am using my measures in a matrix visualisation with three dimensions in the rows (two of them are "projekt" and "aktivitet").

 

My "Measure 1" works just fine: It calculates the "totals" in the matrix visualisation as the sum of only the positive numbers (which is what I'm trying to achieve). 

Measure 1 = IF(HASONEVALUE(DimProjektAktivitet[AktivitetNr]), 
                   IF([BudgetDiff]<0,BLANK(), BudgetDiff]),
                   SUMX(VALUES(DimProjektAktivitet[AktivitetNr]), IF([BudgetDiff]<0,BLANK(),[BudgetDiff])
                )

Unfortunately I need my measure to do a bit more than that - but still calculate the totals in the same manner.

 

My "Measure 2" is as follows, where "Measure 1" is now a part of the RETURN-statement. The essential part related to my question is the SUMX(...) part of the code. 

 

Measure 2 = 
VAR _Budget =
      CALCULATE(
        SUM(FactSagspost[Beloeb]),
        FILTER(DimSagsPostJunk, DimSagsPostJunk[LinjeType] = "Budget"),
        FILTER(DimSagsPostJunk,DimSagsPostJunk[ArtskontoRessource] IN { "Finans", "Ressource" }),
        FILTER(FactProjektRolle,FactProjektRolle[UserPrincipalName] = [KubeInformationCalcEffectiveUsername])
      )
   
VAR _Actual= 
      CALCULATE(
        SUM(FactSagspost[Beloeb]),
        FILTER(DimSagsPostJunk, DimSagsPostJunk[LinjeType] = "Realiseret"),
        FILTER(DimSagsPostJunk, DimSagsPostJunk[ArtskontoRessource] IN {"Finans", "Ressource"}),
        FILTER(FactProjektRolle,FactProjektRolle[UserPrincipalName] = [KubeInformationCalcEffectiveUsername]),
        ALL(DimBudgetnavn)
      ) 
    
VAR _BudgetDiff = _Budget - _Actual

RETURN
      IF(HASONEVALUE(DimProjektAktivitet[AktivitetNr]),
            IF(_Budget < 0, _BudgetDiff,
                  IF(_BudgetDiff > 0, _BudgetDiff, BLANK()
                  )
            ),
            SUMX(VALUES(DimProjektAktivitet[AktivitetNr]), IF(_Budget < 0, _BudgetDiff, 
                                                                  IF(_BudgetDiff > 0,_BudgetDiff,BLANK())
                                                            )
            )
      )

 

The two measures are working just fine, except the fact that "Measure 2" calculates the totals in a different manner than "Measure 1" does: In "Measure 2" the totals become way too large, as if the SUMX()-part has "forgotten" in which context it is.

 

I sincerely hope that somebody can tell me what I did wrong 🙂

2 REPLIES 2
v-yalanwu-msft
Community Support
Community Support

Hi, @Email60 ;

sumx() Sometimes you write vs two measures and the result of merging one measure is different, mainly due to context, which is normal, you can use the formula that meets your needs.
Secondly, if it doesn't solve your problem, can you share the data and hope to output the results? I can't reproduce your formula above.


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-yalanwu-msft 

 

I greatly appreciate your attempt to help 🙂

 

I have to use my "Measure 2", and am trying to figure out how to get the SUMX()-part of the code to act as expected (as in my simpler "Measure 1"). I understand that it's probably not easy to answer as I can't (at the moment) post my data 😞

 

Is it possible that the approach by declaring variables (as in "Measure 2") affects the SUMX-calculation (as compared to just referering to tables in my data, as in "Measure 1")? 

 

Best regards

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

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