Forum Discussion

JustinDoh1's avatar
JustinDoh1
Icon for Post Prodigy rankPost Prodigy
11 months ago
Solved

Quick question about SUMX

I am trying to understand about SUMX. I have uploaded my PBIX file here for reference. I have a measure called "Sumx", and its code looks like this:   Sumx = SUMX(                 VALUES('Date'...
  • VahidDM's avatar
    11 months ago

    JustinDoh1 

     

    SUMX works like this:
    SUMX( Table, Expression ) goes row by row over the table, evaluates the expression for each row, then adds everything up.

    In your measure:

    Sumx = SUMX( VALUES('Date'[DateFormat]), CALCULATE(DISTINCTCOUNT([ClientID])) )


    VALUES('Date'[DateFormat]) creates a one-column table of distinct dates in the current filter context. If you have 1,336 dates, SUMX will iterate 1,336 times.

    For each date, CALCULATE enforces the context to that date only, then runs DISTINCTCOUNT([ClientID]).

    SUMX adds up those daily distinct counts. That means if the same client appears on multiple days, they get counted multiple times (once per day). This is different from just DISTINCTCOUNT([ClientID]) which would count unique clients across the whole period once.

    So the point of VALUES('Date'[DateFormat]) is to drive the iterationm, it forces SUMX to recalculate your measure per date, rather than over the whole set in one go.

     

    If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

    Appreciate your Kudos!! 

     

    LinkedIn|Twitter|Blog |YouTube 

     

  • lbendlin's avatar
    lbendlin
    11 months ago
    Why do we need to even bother with VALUES('Date[DateFormat])? 

    That would be a question for that column. If that column can serve as a primary key then you don't need VALUES.