Forum Discussion

hsalasde's avatar
hsalasde
Regular Visitor
2 years ago
Solved

Log and Delta Calculation

I'm pretty new to BI and have started using the VAR. I'm running a log count and I need to calculate the delta from the previous year for the same month. The results are to be displayed on a table wi...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi hsalasde ,

    amitchandak  makes a good point, I have another method here that I hope will be helpful to you.

    Please try to modify the expression:

    Delta =
    VAR LogIdCountCurrentMonth = CALCULATE(
    DISTINCTCOUNT('Surg Data'[Log]),
    FILTER(
    ALL('Surg Data'),
    YEAR(EARLIER('Surg Data'[Date])) = YEAR('Surg Data'[Date]) &&
    MONTH(EARLIER('Surg Data'[Date])) = MONTH('Surg Data'[Date])
    )
    )
    VAR LogIdCountPreviousYearSameMonth =
    CALCULATE(
    DISTINCTCOUNT('Surg Data'[Log]),
    FILTER(ALL('Surg Data'),
    YEAR('Surg Data'[Date])=YEAR(EARLIER('Surg Data'[Date]))-1&&MONTH('Surg Data'[Date])=MONTH(EARLIER('Surg Data'[Date]))))
    RETURN
    IF(
    YEAR(TODAY()) = 2019 || ISBLANK(LogIdCountPreviousYearSameMonth),
    LogIdCountCurrentMonth,
    LogIdCountCurrentMonth - LogIdCountPreviousYearSameMonth
    )


    The final result is shown below.

    If your Current Period does not refer to this, please clarify in a follow-up reply.

     

    Best Regards,

    Clara Gong

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