Forum Discussion

MarioE's avatar
MarioE
Regular Visitor
1 year ago
Solved

My total is not real in a datediff calculation

Hi colleagues, I need some help from your side, please. I'm trying to calculate the diference between the dates marked as blue. I have created a measure that returns the DIFF PRO Date - MIN Slicer,...
  • girishthimmaiah's avatar
    1 year ago

    Your total is incorrect because the SUM function on your measure is summing all production dates, which skews the calculation at the total level.

    Why is this occurring?
    The SUM(tProcessTab[FechaProduccion]) sums all production dates and produces an unrealistic total date.
    The DATEDIFF is computed on this in-correctly aggregated date.
    The calculation at the row level is correct but at the Total row, it is incorrect.
    How to Fix It?
    Replace SUM with SUMX, which performs row by row and provides the proper total:

    DAX

    DIFF PRO Date - MIN Slicer =
    VAR StartDate = SELECTEDVALUE(tProcessTab[FechaProduccion])
    VAR EndDate = MIN(CalendarioEjecuciones[Date])
    RETURN
    IF(NOT ISBLANK(StartDate), DATEDIFF(StartDate, EndDate, DAY))