Forum Discussion

victorlopes1998's avatar
victorlopes1998
New Member
3 years ago
Solved

Sumx() returning wrong total

Hello all!

 

I'm trying to monthly my weight by distinct count of dates doing:

 

MONTHLY WEIGHT = SUMX(Plan1,
DIVIDE(Plan1[WEIGHT],DISTINCTCOUNT(Plan1[DATE])))
 
 
And I need to get the sum of results line by line to show as a card
 
But I'm getting the wrong result:
 
The correct result is 173+113 = 286 instead of 221.
 

 

 
 

 

 

  • victorlopes1998,

     

    Try this measure:

     

    MONTHLY WEIGHT = 
    VAR vTable =
        ADDCOLUMNS (
            SUMMARIZE ( Plan1, Plan1[DESTINY], Plan1[ORIGIN] ),
            "@Weight", CALCULATE ( SUM ( Plan1[WEIGHT] ) ),
            "@CountDistinctDate", CALCULATE ( DISTINCTCOUNT ( Plan1[DATE] ) )
        )
    VAR vResult =
        SUMX ( vTable, DIVIDE ( [@Weight], [@CountDistinctDate] ) )
    RETURN
        vResult

     

     

2 Replies

  • victorlopes1998,

     

    Try this measure:

     

    MONTHLY WEIGHT = 
    VAR vTable =
        ADDCOLUMNS (
            SUMMARIZE ( Plan1, Plan1[DESTINY], Plan1[ORIGIN] ),
            "@Weight", CALCULATE ( SUM ( Plan1[WEIGHT] ) ),
            "@CountDistinctDate", CALCULATE ( DISTINCTCOUNT ( Plan1[DATE] ) )
        )
    VAR vResult =
        SUMX ( vTable, DIVIDE ( [@Weight], [@CountDistinctDate] ) )
    RETURN
        vResult