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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
lightsaberluke
Regular Visitor

Shift Data by one row down

Hi, I am trying to create a new measure where I have my data from another row just shifted down one. I found a video that used the following formula but it did not work: 

Previous Year = Calculate (distinctcount('Sheet1' [Order ID]), DATEADD(Sheet1' [Order Date].[Date], -1, YEAR))

What I have: 

lightsaberluke_1-1728486555846.png

What I expect: 

lightsaberluke_2-1728486691920.png

 

1 ACCEPTED SOLUTION
v-zhengdxu-msft
Community Support
Community Support

Hi @lightsaberluke 

 

Please try this:

Here's a sample:

Table:

vzhengdxumsft_0-1728541198295.png

Then add an index column in powerquery:

vzhengdxumsft_1-1728541353248.png

Next add a measure:

 

MEASURE =
VAR _currentIndex =
    MAX ( 'Table'[Index] )
VAR _previousIndex =
    CALCULATE (
        MAX ( 'Table'[Index] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Index] < _currentIndex )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Values] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Index] = _previousIndex )
    )

 

The result is as follow:

vzhengdxumsft_2-1728541434777.png

 

Or if you have an date column:

vzhengdxumsft_3-1728541478622.png

You can try this measure without an index column:

 

MEASURE 2 =
VAR _currentDate =
    MAX ( 'Table'[Date] )
VAR _PreviousDate =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Date] < _currentDate )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Values] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Date] = _PreviousDate )
    )

 

 The result is as follow:

vzhengdxumsft_4-1728541692994.png

 

 

Best Regards

Zhengdong Xu
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-zhengdxu-msft
Community Support
Community Support

Hi @lightsaberluke 

 

Please try this:

Here's a sample:

Table:

vzhengdxumsft_0-1728541198295.png

Then add an index column in powerquery:

vzhengdxumsft_1-1728541353248.png

Next add a measure:

 

MEASURE =
VAR _currentIndex =
    MAX ( 'Table'[Index] )
VAR _previousIndex =
    CALCULATE (
        MAX ( 'Table'[Index] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Index] < _currentIndex )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Values] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Index] = _previousIndex )
    )

 

The result is as follow:

vzhengdxumsft_2-1728541434777.png

 

Or if you have an date column:

vzhengdxumsft_3-1728541478622.png

You can try this measure without an index column:

 

MEASURE 2 =
VAR _currentDate =
    MAX ( 'Table'[Date] )
VAR _PreviousDate =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Date] < _currentDate )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Values] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Date] = _PreviousDate )
    )

 

 The result is as follow:

vzhengdxumsft_4-1728541692994.png

 

 

Best Regards

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

ryan_mayu
Super User
Super User

 @lightsaberluke 

 

you need to create a datetable. 

 

The column for the first parameter is from date table , not the fact table.

 

= DATEADD(DateTime[DateKey],-1,year)

 

https://learn.microsoft.com/en-us/dax/dateadd-function-dax?wt.mc_id=DP-MVP-5004616

 

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




d_rohlfs
Resolver I
Resolver I

Hi @lightsaberluke
I think there might be a way to do this in DAX, but I have found it much easier to do this in Power Query. Follow along with this blog, but just reverse the column that you choose in the merge (instead of From 1 to From 0, do From 0 to From 1).
Power BI – Reference a Previous Row in Power Query : :: Welcome To EPM Strategy ::

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.