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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
byr10112
Microsoft Employee
Microsoft Employee

Calculated Column - Previous Month's Data with Multiple Filters

I have the following table, where the monthly account scores are broken down by category and customer ID. For each ID and category, I would like to get the previous month's data as a calculated column. I tried creating this as a measure but the matrix totals are not accurate, and I was told that creating this as a calculated column can solve my issue. Any help is appreciated:

Current Table:

Customer IDMonthCategoryScore
100101-02-2022Security.98
100101-02-2022Cost.84
100101-02-2022Other

.70

100101-03-2022Security.91
100101-03-2022Cost.92

 

Desired Table:

Customer IDMonthCategoryScoreLast Month Score
100101-02-2022Security.98 
100101-02-2022Cost.84 
100101-02-2022Other

.70

 

100101-03-2022Security.91.98
100101-03-2022Cost.92.84

 

I will then be calculating the percent point change in each score. 

1 ACCEPTED SOLUTION
Samarth_18
Community Champion
Community Champion

Hi @byr10112 ,

Please create a column like below:-

Column =
VAR _lastmonth =
    IF ( MONTH ( 'Table (4)'[Month] ) = 1, 12, MONTH ( 'Table (4)'[Month] ) - 1 )
VAR _year =
    IF (
        MONTH ( 'Table (4)'[Month] ) = 1,
        YEAR ( 'Table (4)'[Month] ) - 1,
        YEAR ( 'Table (4)'[Month] )
    )
RETURN
    CALCULATE (
        MAX ( 'Table (4)'[Score] ),
        FILTER (
            ALL ( 'Table (4)' ),
            'Table (4)'[Customer ID] = EARLIER ( 'Table (4)'[Customer ID] )
                && 'Table (4)'[Category] = EARLIER ( [Category] )
                && MONTH ( 'Table (4)'[Month] ) = _lastmonth
                && YEAR ( 'Table (4)'[Month] ) = _year
        )
    )

Output:-

Samarth_18_0-1649690626835.png

 

Thanks,

Samarth

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

View solution in original post

1 REPLY 1
Samarth_18
Community Champion
Community Champion

Hi @byr10112 ,

Please create a column like below:-

Column =
VAR _lastmonth =
    IF ( MONTH ( 'Table (4)'[Month] ) = 1, 12, MONTH ( 'Table (4)'[Month] ) - 1 )
VAR _year =
    IF (
        MONTH ( 'Table (4)'[Month] ) = 1,
        YEAR ( 'Table (4)'[Month] ) - 1,
        YEAR ( 'Table (4)'[Month] )
    )
RETURN
    CALCULATE (
        MAX ( 'Table (4)'[Score] ),
        FILTER (
            ALL ( 'Table (4)' ),
            'Table (4)'[Customer ID] = EARLIER ( 'Table (4)'[Customer ID] )
                && 'Table (4)'[Category] = EARLIER ( [Category] )
                && MONTH ( 'Table (4)'[Month] ) = _lastmonth
                && YEAR ( 'Table (4)'[Month] ) = _year
        )
    )

Output:-

Samarth_18_0-1649690626835.png

 

Thanks,

Samarth

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors