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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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