Forum Discussion

DataStraine's avatar
DataStraine
Advocate I
5 years ago
Solved

Dynamic previous row value?

I have a few formulas that I am using to calculate customer count, churned customer count, and previous churned customer running total. What I am trying to do is figure out a way to allow for proper ...
  • MFelix's avatar
    5 years ago

    Hi DataStraine ,

     

    You issue is that you are forcing the calculation to be based on the month since you are using the dateadd.

     

    What can be done is to make use of a swith formula and then change the scope of your measure something similar to:

    Customer Count Prev. Month =
    SWITCH (
        TRUE (),
        ISINSCOPE ( 'Calendar'[Month] ), CALCULATE ( [Customer Count], DATEADD ( 'Calendar'[Date], -1, MONTH ) ),
        ISINSCOPE ( 'Calendar'[Quarter] ), CALCULATE ( [Customer Count], DATEADD ( 'Calendar'[Date], -1, QUARTER ) ),
        ISINSCOPE ( 'Calendar'[Year] ), CALCULATE ( [Customer Count], DATEADD ( 'Calendar'[Date], -1, YEAR ) )
    )

     

    also there is some blogs about custom periods and this type of calculations:

    https://radacad.com/previous-dynamic-period-dax-calculation

    https://www.daxpatterns.com/month-related-calculations/