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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
subhash_mn
New Member

Get Previous Year data

Hello, I am looking for formula that can get me previous year data from the same table. Below is a example table

subhash_mn_0-1649789827742.png

I need in PowerQuery

1 ACCEPTED SOLUTION
tackytechtom
Most Valuable Professional
Most Valuable Professional

Hi @subhash_mn ,

 

Here a solution:

tomfox_0-1649795761961.png

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VcxBCgAgCETRu7huMSpBnSW8/zXKLNDVh8foWsTUSMDzhEHWvghcehYPjyxyc0XSFQrFtpBHH2l6jmqxdrMN", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Item = _t, Year = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Item", Int64.Type}, {"Year", Int64.Type}, {"Value", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "NextYear", each [Year] + 1),
    #"Merged Queries" = Table.NestedJoin(#"Added Custom", {"Item", "Year"}, #"Added Custom", {"Item", "NextYear"}, "Added Custom", JoinKind.LeftOuter),
    #"Expanded Added Custom" = Table.ExpandTableColumn(#"Merged Queries", "Added Custom", {"Item", "Year", "Value", "NextYear"}, {"Added Custom.Item", "Added Custom.Year", "Added Custom.Value", "Added Custom.NextYear"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Added Custom",{"NextYear", "Added Custom.Item", "Added Custom.Year", "Added Custom.NextYear"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Added Custom.Value", "PriorYr"}})
in
    #"Renamed Columns"

Note, my table is called table13.

 

Let me know if this solved your issue 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

2 REPLIES 2
tackytechtom
Most Valuable Professional
Most Valuable Professional

Hi @subhash_mn ,

 

Here a solution:

tomfox_0-1649795761961.png

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VcxBCgAgCETRu7huMSpBnSW8/zXKLNDVh8foWsTUSMDzhEHWvghcehYPjyxyc0XSFQrFtpBHH2l6jmqxdrMN", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Item = _t, Year = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Item", Int64.Type}, {"Year", Int64.Type}, {"Value", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "NextYear", each [Year] + 1),
    #"Merged Queries" = Table.NestedJoin(#"Added Custom", {"Item", "Year"}, #"Added Custom", {"Item", "NextYear"}, "Added Custom", JoinKind.LeftOuter),
    #"Expanded Added Custom" = Table.ExpandTableColumn(#"Merged Queries", "Added Custom", {"Item", "Year", "Value", "NextYear"}, {"Added Custom.Item", "Added Custom.Year", "Added Custom.Value", "Added Custom.NextYear"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Added Custom",{"NextYear", "Added Custom.Item", "Added Custom.Year", "Added Custom.NextYear"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Added Custom.Value", "PriorYr"}})
in
    #"Renamed Columns"

Note, my table is called table13.

 

Let me know if this solved your issue 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Thanks Tom!!! Appreciate the help

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.