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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Anonymous
Not applicable

Price variation between dates

 
Hi,

 

Im traing to calculate the price variation between two dates. 

 

isabel_herrero0_0-1659920105711.png

 

 

Is just a rest but i dont know how to do it.

 

Thank you

1 ACCEPTED SOLUTION
jbwtp
Memorable Member
Memorable Member

Hi @Anonymous,

 

Assuming that the data is ordered by date:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XdHLDcQwCATQXnyOCGDzcS1W+m9jV7CRYK9PyMzgcwbdSDcj87jGVlAez3UGV53gEjqrMqwduqoKoIVKn3UK1aobdIZaVQJaoV4VwTLD7rOSs4S9hmcNop6C8w3iHmNp8uxN3kdWD+K/ldJXcjYk7aezPAfZ3+082TvvPAi1lvZOM/bc8v2A5wM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Brent = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Brent", type number}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Var", each 0, type number),
    ToList = Table.ToRecords(#"Added Custom"),
    Calculate = List.Accumulate(List.Skip(ToList), {List.First(ToList)}, (a,n)=> a & {Record.TransformFields(n,{"Var", (x)=> n[Brent] - List.Last(a)[Brent]})}),
    Output = Table.FromRecords(Calculate, Value.Type(#"Added Custom"))
in
    Output

 

Kind regards,

John

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Thank you! Helpful 😁

 

jbwtp
Memorable Member
Memorable Member

Hi @Anonymous,

 

Assuming that the data is ordered by date:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XdHLDcQwCATQXnyOCGDzcS1W+m9jV7CRYK9PyMzgcwbdSDcj87jGVlAez3UGV53gEjqrMqwduqoKoIVKn3UK1aobdIZaVQJaoV4VwTLD7rOSs4S9hmcNop6C8w3iHmNp8uxN3kdWD+K/ldJXcjYk7aezPAfZ3+082TvvPAi1lvZOM/bc8v2A5wM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Brent = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Brent", type number}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Var", each 0, type number),
    ToList = Table.ToRecords(#"Added Custom"),
    Calculate = List.Accumulate(List.Skip(ToList), {List.First(ToList)}, (a,n)=> a & {Record.TransformFields(n,{"Var", (x)=> n[Brent] - List.Last(a)[Brent]})}),
    Output = Table.FromRecords(Calculate, Value.Type(#"Added Custom"))
in
    Output

 

Kind regards,

John

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

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.

Top Kudoed Authors