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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Column with value from previous day / row

Hey there

 

I have a table for Add, Minus, Net Mvmt and Closing bal by date setup as columns in PowerBI.

 

How can I add a column (Opening Bal) which takes the Closing Balance from previous date?

 

Thanks!

 

 AddMinusNet MvmtClosing BalOpening Bal
6-Jan100505050 
7-Jan200 20025050
8-Jan300100200450250
1 ACCEPTED SOLUTION
PattemManohar
Community Champion
Community Champion

@Anonymous Please add and Index column in Power Query Editor and then use the below DAX as New Column.

 

If your data is not in sorted order by date then add a Rank column as below instead of Index and then use this Rank field in place of Index in DAX formula

 

Rnk = RANKX(Test169PrevRow,Test169PrevRow[Date],,ASC)

 

OpeningBal = LOOKUPVALUE(Test169PrevRow[Closing Bal],Test169PrevRow[Index],Test169PrevRow[Index]-1)

image.png





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

Proud to be a PBI Community Champion




View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

HI @Anonymous,

 

If your table not contain duplicate date, you can direct use data as iterator to looping your records.

Opening Bal =
VAR prevDate =
    CALCULATE (
        MAX ( Table[Date] ),
        FILTER ( ALL ( Table ), [Date] < EARLIER ( Table[Date] ) )
    )
RETURN
    LOOKUPVALUE ( Table[Closing Bal], Table[Date], prevDate )

If not, you can consider to use PattemManohar's suggestion to add index column as iterator.

 

Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
PattemManohar
Community Champion
Community Champion

@Anonymous Please add and Index column in Power Query Editor and then use the below DAX as New Column.

 

If your data is not in sorted order by date then add a Rank column as below instead of Index and then use this Rank field in place of Index in DAX formula

 

Rnk = RANKX(Test169PrevRow,Test169PrevRow[Date],,ASC)

 

OpeningBal = LOOKUPVALUE(Test169PrevRow[Closing Bal],Test169PrevRow[Index],Test169PrevRow[Index]-1)

image.png





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

Proud to be a PBI Community Champion




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors