Forum Discussion
Last month status
Hello Everybody,
I have a problem that I´m not getting finish it. Could you help me please?
I want to create a collumn that show me the "last month status".
| Produto | Data | Status2 | Last month status |
| 1 | 22/01/2022 00:00 | Alerta | |
| 1 | 31/01/2022 00:00 | Alerta | Alerta |
| 1 | 12/02/2022 00:00 | defeito | |
| 1 | 28/02/2022 00:00 | defeito | defeito |
| 1 | 23/03/2022 00:00 | defeito | |
| 1 | 24/03/2022 00:00 | Alerta | |
| 1 | 26/03/2022 00:00 | Alerta | Alerta |
I tried to do it using summarize, but I didn´t get. Below is what I want to do: (this example I inform only 1 product,but there are more than 1, like 2,3,4)
| Produto | Data | Status2 | Last moth status |
| 1 | 31/01/2022 00:00 | Alerta | Alerta |
| 1 | 28/02/2022 00:00 | defeito | defeito |
| 1 | 26/03/2022 00:00 | Alerta | Alerta |
leandross89 , Create a new column
var _month = eomonth([Data],0)
var _max = maxx(filter(table, [Produto] =earlier([Produto]) && eomonth([Data],-1) = _month ), [Data])
return
maxx(filter(table, [Produto] =earlier([Produto]) && [Data] = _max ), [Status2])
3 Replies
- amitchandak
Super User
leandross89 , Create a new column
var _month = eomonth([Data],0)
var _max = maxx(filter(table, [Produto] =earlier([Produto]) && eomonth([Data],-1) = _month ), [Data])
return
maxx(filter(table, [Produto] =earlier([Produto]) && [Data] = _max ), [Status2])- leandross89
Helper II
Dear Thank you a lot. I had changing this part "[Data],-1" to [Data],0), it worked very well. How Can I study dax, do you know some content/website/youtube to share with?
- PC2790
Community Champion
See if this code in Power Query fulfills your requirement:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTLUNzLSNzIwMgKyHXNSi0oSlWJ1YFLGhjikjPQN4bpSUtNSM0vykeSMLHDJGesbGeORM8FhHVDKDF0qFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Produto = _t, Data = _t, Status2 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Produto", Int64.Type}, {"Data", type date}, {"Status2", type text}}), #"Inserted Month" = Table.AddColumn(#"Changed Type", "Month", each Date.Month([Data]), Int64.Type), #"Grouped Rows" = Table.Group(#"Inserted Month", {"Month"}, {{"MaxDate", each List.Max([Data]), type nullable date}, {"Status", each List.Max([Status2]), type nullable text}, {"Product", each List.Max([Produto]), type nullable number}}), #"Removed Columns" = Table.RemoveColumns(#"Grouped Rows",{"Month"}) in #"Removed Columns"