Forum Discussion

ero1's avatar
ero1
Frequent Visitor
2 years ago
Solved

Add custom column with previous values

I'm in power query trying to add two custom columns. One with the previous values by month and another with the previous values by year. I need these to calculate another two columns with % MoM and %...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi ero1 

    Did you use the code in power query? The code Greg_Deckler  and i offered is used in power bi desktop, if you want to achieve this in power query you need to use the code i offered at 4th message.

    In power query, create the following custom column.

    Custom column1

     

    =List.Max(Table.SelectRows(#"Changed Type",(x)=>x[City]=[City] and x[Date]=Date.AddMonths([Date],-1))[Value])

     

    Custom column2

     

    List.Max(Table.SelectRows(#"Changed Type",(x)=>x[City]=[City] and x[Date]=Date.AddYears([Date],-1))[Value])

     

    replace the #"Changed type"with the last step name of your query.(Format:#"xxxxx")

    If the solutions @Greg_Deckler  and i offered help you solve the provlem, please consider to mark them as solutions

     

    Best Regards!

    Yolo Zhu

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