Forum Discussion
Add custom column with previous values
- Anonymous2 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.
Hello, thanks for you reply, although I have to confess that I don't understand this decompresses binary data part. I tried to use the solution @Greg_Deckler posted, but so far I haven't been able to figure how to make it work. Perhaps you could tell me what part I'm missing.
Hi ero1
Thanks for your quick reply, if you want to use calculated column.
You can try the following calculated column.
Previous Month =
VAR lastmonth =
EOMONTH ( Table1[Date], -1 )
RETURN
CALCULATE (
SUM ( Table1[Valor] ),
ALLEXCEPT ( Table1, Table1[City] ),
EOMONTH ( Table1[Date], 0 ) = lastmonth
)
Previous year =
VAR lastyear =
EOMONTH ( Table1[Date], -12 )
RETURN
CALCULATE (
SUM ( Table1[Valor] ),
ALLEXCEPT ( Table1, Table1[City] ),
EOMONTH ( Table1[Date], 0 ) = lastyear
)
Output
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.
- ero12 years agoFrequent Visitor
I'm new and terrible at this. Haven't been able to make your suggestion or Greg's work. The worst part, is that I have no clue as to why. I've checked, recheked and made adjustments to both codes and keep getting "Token Eof expected".
- Anonymous2 years agoNot applicable
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.
- ero12 years agoFrequent Visitor
Thanks. I was using the other code in power query, but now that you made me aware of my mistake it works fine. You made my day. Kudos