excelpowerbidax

Trying to calculate change over time using a SUMX function with DAX. but the value I get is cumulative value--how can I get the non-cumulative value?


I have a dataset that looks something like this:

Interval ID Calls Handled Total Handle Time
8:00 123456 1 900
9:00 123456 2 2100
10:00 123456 4 4100

This has multiple IDs, more intervals and so on. Keep in mind that the data is listed in the starting interval. The information on columns Calls Handled and AHT is cumulative, so it will contain information on the previous intervals too. Now, you can intuitively assume based on these columns that number of New Calls Handled is 1 at 8:00, 1 at 9:00 and 2 and 10:00.

Now, you probably are going to ask the reasonable thing -- why not change the way the data is obtained, so that the data is not cumulative? At the moment, there's nothing I can do about it.

I have a solution I am not quite happy with, since I am sure I am just not correctly understanding the appropriate context for the expression.

Say the data above is called Data.

After importing it into Excel's Power Pivot, I created a column that does this:

New Calls Handled:=
  Data[Calls Handled] - 
  LOOKUPVALUE(
    Data[Calls Handled],
    Data[Interval],
    CALCULATE( 
      MAX( Data[Interval] ),
      FILTER( Data, Data[Interval] < EARLIER( Data[Interval] ) )
    ),
    Data[ID], Data[ID] 
  )

If I sum this up, it works just fine. I get 1 at 8:00, 1 at 9:00 and 2 at 10:00 when the table has the interval filter or filter context applied.

Now, based on this, I tried turning it into SUMX expression,

New Calls Handled_2:=
  SUMX(
    Data,
    Data[Calls Handled] - 
    LOOKUPVALUE(
      Data[Calls Handled],
      Data[Interval],
      CALCULATE( 
        MAX(Data[Interval]),
        FILTER( Data, Data[Interval] < EARLIER( Data[Interval] ) )
      ),
      Data[ID], Data[ID]
    )
  )

Upon attempting to use this one, I get 1 at 8:00, 2 at 9:00 and 4 at 10:00. I reckon the problem has got to be related to the table and an inappropriate handling of the row context, since right now I'm using a basic, unfiltered Data table. But for the life of me, I can't seem to find out why it is not working.

I have tried to apply some filters to it, but it only seems to lead to worse results--ALL(Data) and ALLSELECTED(Data) return larger numbers than the total, and ALLEXCEPT( Data, Data[Interval]) clearly will not work, but it will clearly not work, though I had to try anyway.

What am I doing wrong in the SUMX expression? What am I not understanding about the row context?


Solution

  • It is working though - you are using SUMX so it is summing the previous values.

    What are you trying to achieve?

    I suspect what you are after is a Calculated Column not a Measure.
    Double click on Add Column header at the far right of your columns. Enter the name of your new column New Calls Handled, then hit return. Then in the formula bar, add your first expression:

    Calculated column

    Additional
    If you really need it as a Measure then you will need to use ALL in your filter so that it looks at the whole table (and not just the current row). Try:

    New Calls Handled_2:=
      SUMX(
        Data,
        Data[Calls Handled] - 
        LOOKUPVALUE(
          Data[Calls Handled],
          Data[Interval],
          CALCULATE( 
            MAX(Data[Interval]),
            FILTER( ALL(Data), Data[Interval] < EARLIER( Data[Interval] ) )
          ),
          Data[ID], Data[ID]
        )
      )