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! Learn more

Reply
Anonymous
Not applicable

Lagged Values

Hi, I have a table similar to below. 

RegionMonth of Period EndAttributeValue
State A4/1/2022Homes Sold24%
State A3/1/2022Homes Sold22%
State A2/1/2022Homes Sold5%
State A1/1/2022Homes Sold6%
State B5/1/2022Home Price8%
State B4/1/2022Home Price9%
State B3/1/2022Home Price2%
State B2/1/2022Home Price34%
State B1/1/2022Home Price22%

 

I want to create a dynamic column of lagged values such that the period of lag (1 month/2 months/3 months/...) can be selected via a slicer. The calculation of the lag column depicted in the last 3 columns below:

RegionMonth of Period EndAttributeValueLagged by 1 (Minus 1 month)Lagged by 2 (Minus 2 months)Lagged by 3 (Minus 3 months)
State A4/1/2022Homes Sold24%22%5%..
State A3/1/2022Homes Sold22%5%6%..
State A2/1/2022Homes Sold5%6%-..
State A1/1/2022Homes Sold6%--..
State B5/1/2022Home Price8%9%2%..
State B4/1/2022Home Price9%2%34%..
State B3/1/2022Home Price2%34%22%..
State B2/1/2022Home Price34%22%-..
State B1/1/2022Home Price22%--..

 

Please help me out with what will work. Will prefer the DAX to be as simple as possible since I do not have a coding background. Thanks.

2 ACCEPTED SOLUTIONS
v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

According to your description, here's my solution.

Create three calculated columns.

Lagged by 1 =
MAXX (
    FILTER (
        'Table',
        'Table'[Region] = EARLIER ( 'Table'[Region] )
            && EOMONTH ( 'Table'[Month of Period End], 0 )
                = EOMONTH ( EARLIER ( 'Table'[Month of Period End] ), -1 )
    ),
    'Table'[Value]
)
Lagged by 2 =
MAXX (
    FILTER (
        'Table',
        'Table'[Region] = EARLIER ( 'Table'[Region] )
            && EOMONTH ( 'Table'[Month of Period End], 0 )
                = EOMONTH ( EARLIER ( 'Table'[Month of Period End] ), -2 )
    ),
    'Table'[Value]
)
Lagged by 3 =
MAXX (
    FILTER (
        'Table',
        'Table'[Region] = EARLIER ( 'Table'[Region] )
            && EOMONTH ( 'Table'[Month of Period End], 0 )
                = EOMONTH ( EARLIER ( 'Table'[Month of Period End] ), -3 )
    ),
    'Table'[Value]
)

Get the result:

vkalyjmsft_0-1666664139854.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

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

Hi @Anonymous ,

My pleasure!

You can do it in Power Query. Add three custom columns.

try Table.SelectRows(#"Changed Type",(x)=>x[Region]=[Region]and x[Month of Period End]<[Month of Period End])[Value]{0} otherwise ""
try Table.SelectRows(#"Changed Type",(x)=>x[Region]=[Region]and x[Month of Period End]<[Month of Period End])[Value]{1} otherwise ""
try Table.SelectRows(#"Changed Type",(x)=>x[Region]=[Region]and x[Month of Period End]<[Month of Period End])[Value]{2} otherwise ""

Result:

vkalyjmsft_0-1666750693237.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

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
v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

According to your description, here's my solution.

Create three calculated columns.

Lagged by 1 =
MAXX (
    FILTER (
        'Table',
        'Table'[Region] = EARLIER ( 'Table'[Region] )
            && EOMONTH ( 'Table'[Month of Period End], 0 )
                = EOMONTH ( EARLIER ( 'Table'[Month of Period End] ), -1 )
    ),
    'Table'[Value]
)
Lagged by 2 =
MAXX (
    FILTER (
        'Table',
        'Table'[Region] = EARLIER ( 'Table'[Region] )
            && EOMONTH ( 'Table'[Month of Period End], 0 )
                = EOMONTH ( EARLIER ( 'Table'[Month of Period End] ), -2 )
    ),
    'Table'[Value]
)
Lagged by 3 =
MAXX (
    FILTER (
        'Table',
        'Table'[Region] = EARLIER ( 'Table'[Region] )
            && EOMONTH ( 'Table'[Month of Period End], 0 )
                = EOMONTH ( EARLIER ( 'Table'[Month of Period End] ), -3 )
    ),
    'Table'[Value]
)

Get the result:

vkalyjmsft_0-1666664139854.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

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

Anonymous
Not applicable

Hi, thank you for the answer. This works if I did not have to use a slicer to select the number of months I wanted to lag my values by. However to use a slicer, I need to pivot these three rows which can only be done in PowerQuery. Could I replicate the same calculated columns in PowerQuery using M?

 

Hi @Anonymous ,

My pleasure!

You can do it in Power Query. Add three custom columns.

try Table.SelectRows(#"Changed Type",(x)=>x[Region]=[Region]and x[Month of Period End]<[Month of Period End])[Value]{0} otherwise ""
try Table.SelectRows(#"Changed Type",(x)=>x[Region]=[Region]and x[Month of Period End]<[Month of Period End])[Value]{1} otherwise ""
try Table.SelectRows(#"Changed Type",(x)=>x[Region]=[Region]and x[Month of Period End]<[Month of Period End])[Value]{2} otherwise ""

Result:

vkalyjmsft_0-1666750693237.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

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

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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