Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Last year sales Column in Query Editor

Hi All,

 

How to calculate last year sales for same time period in Query editor?I need to use Unpivot option hence i need to claculate those in Edit query.

 

Thanks in Advance!

 

MonthSaleLast Year Sale
Jan-19100 
Feb-19200 
Mar-19300 
Apr-19400 
May-19500 
Jun-19600 
Jul-19700 
Aug-19800 
Sep-19900 
Oct-191000 
Nov-191100 
Dec-191200 
Jan-201300100
Feb-201400200
Mar-201500300
Apr-201600400
May-201700500
Jun-201800600
Jul-201900700
Aug-202000800
Sep-202100900
Oct-2022001000
Nov-2023001100
Dec-2024001200
  • Hi Anonymous ,

     

    It need to merge tables. Please try like this:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vc/JDYBADEPRXnJGIsnstYzovw0EDgq+Pvngv7fYaaerLTnEVOU6tniSB5WkElSTalBLakE9qQeNpBE0k2bQSlpBpvQ18B/wFdgvwb4GDF0fK5QKq9QKaxQL61QLG5QLm9QLWxT8misVw4yTgc7JwMLJwDflugE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Month = _t, Sale = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Month", type date}, {"Sale", Int64.Type}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Date.AddYears([Month],-1)),
        #"Merged Queries" = Table.NestedJoin(#"Added Custom", {"Custom"}, #"Added Custom", {"Month"}, "Added Custom", JoinKind.LeftOuter),
        #"Expanded Added Custom" = Table.ExpandTableColumn(#"Merged Queries", "Added Custom", {"Sale"}, {"Sale.1"}),
        #"Removed Columns" = Table.RemoveColumns(#"Expanded Added Custom",{"Custom"})
    in
        #"Removed Columns"

     

5 Replies