Forum Discussion

JulietZhu's avatar
JulietZhu
Icon for Helper IV rankHelper IV
8 years ago
Solved

Average payment for previous month

I need average payment for last month. For example, if I choose any date for  Feb, average payment for Jan need be calculated. Each day payment for Feb will be compared to overal average payment in J...
  • mattbrice's avatar
    mattbrice
    8 years ago

    I downloaded and looked at your file.  Only change I see to make is to remove the ".Date" part.  Try this:

     

    Avg_PreviousMonth_payment =
    CALCULATE (
        AVERAGE ( DataFromDB[Payment_Amt] ),
        PREVIOUSMONTH ( CalendarTable[Date] )
    )
  • Vvelarde's avatar
    Vvelarde
    8 years ago

    JulietZhu

     

    One way to reduce is:

     

    Creating a calculated column in your calendar table

     

    DaysinMonth =
    DATEDIFF (
        STARTOFMONTH ( CalendarTable[Date] );
        ENDOFMONTH ( CalendarTable[Date] );
        DAY
    )
        + 1

    And in the measure:

     

    TotalPayment_PreviousMonth =
    VAR DaysinPrevMonth =
        CALCULATE (
            SELECTEDVALUE ( CalendarTable[DaysinMonth] );
            PREVIOUSMONTH ( CalendarTable[Date] )
        )
    RETURN
        DIVIDE (
            CALCULATE (
                SUM ( DataFromDB[Payment_Amt] );
                PREVIOUSMONTH ( CalendarTable[Date] )
            );
            DaysinPrevMonth
        )

    Regards

     

    Victor

    Lima - Peru