Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
jamesholland198
Frequent Visitor

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 December row with Billing value 165.24, I'd want to add next to it the value for the same SageRef from 1st November, so 158.42

 

Any help appreciated, thanks.

 

SageRefMonthBilling
Example1Aug-20114.56
Example1Sep-20114.56
Example1Oct-20157.45
Example1Nov-20158.42
Example1Dec-20165.24
Example2Aug-20156.98
Example2Sep-20167.23
Example2Oct-20162.56
Example2Nov-20194.87
Example2Dec-20225.26
Example3Aug-20220.89
Example3Sep-20217.21
Example3Oct-20210.89
Example3Nov-20859.65
Example3Dec-20364.85

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @jamesholland198 

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

Unrelated Month Table:

1.png

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.

2.png

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. 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @jamesholland198 

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

Unrelated Month Table:

1.png

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.

2.png

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. 

Perfect, thanks very much

amitchandak
Super User
Super User

@jamesholland198 , with help from date table you can have month behind measure

 

example measure

 

Month behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Month))

 

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.