Forum Discussion

jamesholland198's avatar
jamesholland198
Frequent Visitor
5 years ago
Solved

Month on Month Comparison based on another value

Hi,   I have the below table.  I want to add a 4th column, showing what the Billing value was for the relevant SageRef for the previous month.   So for example for SageRef Example1, on the 1st De...
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi jamesholland198 

    I think your Month column is text type, you may need to build a Month table as below.

    Unrelated Month Table:

    Then add a YearMonth column in your sample table.

    YearMonth =
    VAR _MonthName =
        LEFT ( 'Table'[Month], 3 )
    VAR _MonthNum =
        CALCULATE (
            SUM ( 'Month'[MonthNumber] ),
            FILTER ( 'Month', 'Month'[Month] = _MonthName )
        )
    VAR _YearNum =
        FORMAT ( RIGHT ( 'Table'[Month], 2 ), "General Number" ) + 2000
    RETURN
        _YearNum * 100 + _MonthNum

    Build the billing in previous month column by YearMonth column.

    Billing in Previous Month = 
    VAR _PreviousMonth =
        MAXX (
            FILTER (
                'Table',
                'Table'[SageRef] = EARLIER ( 'Table'[SageRef] )
                    && 'Table'[YearMonth] < EARLIER ( 'Table'[YearMonth] )
            ),
            'Table'[YearMonth]
        )
    RETURN
        CALCULATE (
            SUM ( 'Table'[Billing] ),
            FILTER (
                'Table',
                'Table'[SageRef] = EARLIER ( 'Table'[SageRef] )
                    && 'Table'[YearMonth] = _PreviousMonth
            )
        )

    Result is as below.

    Best Regards,

    Rico Zhou

     

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