Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I want to compare the last status with the secondlast status.
And i want to do that in M.
I manage to create a set of data that only contains the last created status. What I want now is a st in which the second-last status is visible.
Is that possible? for example in the advanced editor?
This is my set of data.
ID_Main | ID_Status | Status | Date_status |
1 | 1 | Red | 1-1-2019 |
2 | 2 | Orange | 2-1-2019 |
2 | 3 | Green | 3-1-2019 |
2 | 4 | Red | 4-1-2019 |
3 | 5 | Orange | 5-1-2019 |
4 | 6 | Green | 6-1-2019 |
5 | 7 | Red | 7-1-2019 |
5 | 8 | Orange | 8-1-2019 |
5 | 9 | Green | 9-1-2019 |
6 | 10 | Red | 10-1-2019 |
7 | 11 | Orange | 11-1-2019 |
7 | 12 | Green | 12-1-2019 |
@henriwestra I tried it in the following way. Please let me know if it works for you
let Source = Web.Page(Web.Contents("https://community.powerbi.com/t5/Desktop/Group-by-the-secondlast-date/m-p/658233#M315999")), Data0 = Source{0}[Data], #"Promoted Headers" = Table.PromoteHeaders(Data0, [PromoteAllScalars=true]), #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"ID_Main", Int64.Type}, {"ID_Status", Int64.Type}, {"Status", type text}, {"Date_status", type date}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"ID_Main"}, {{"AD", each _, type table}}), #"Added Custom" = Table.AddColumn(#"Grouped Rows", "C", each let Source=[AD], X=Table.AddIndexColumn(Table.Sort(Source,{{"Date_status", Order.Descending}}),"IX",1,1), Y= Table.AddColumn(X, "Custom", each Table.RowCount(X)) in Y), #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"AD"}), #"Expanded C" = Table.ExpandTableColumn(#"Removed Columns", "C", {"ID_Status", "Status", "Date_status", "IX", "Custom"}, {"ID_Status", "Status", "Date_status", "IX", "Custom"}), #"Grouped Rows1" = Table.Group(#"Expanded C", {"ID_Main", "Custom"}, {{"AD", each _, type table}}), #"Added Custom1" = Table.AddColumn(#"Grouped Rows1", "Custom.1", each if [Custom]>1 then let Source=[AD], X= Table.SelectRows(Source, each ([IX] = 2)) in X else let Source=[AD], X= Table.SelectRows(Source, each ([IX] = 1)) in X), #"Removed Other Columns" = Table.SelectColumns(#"Added Custom1",{"Custom.1"}), #"Expanded Custom.1" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom.1", {"ID_Main", "ID_Status", "Status", "Date_status", "IX", "Custom"}, {"ID_Main", "ID_Status", "Status", "Date_status", "IX", "Custom"}), #"Added Custom2" = Table.AddColumn(#"Expanded Custom.1", " 2nd Last Logic", each "If ID_Main count =1 then pick up the same row #(cr) else pick up the 2nd row in Descending Order #(cr)based on Date_Status"), #"Removed Other Columns1" = Table.SelectColumns(#"Added Custom2",{"ID_Main", "ID_Status", "Status", "Date_status", " 2nd Last Logic"}) in #"Removed Other Columns1"
Hy @smpa1,
I get an error when creating column C, see print screen. Can you tell me what I am doing wrong?
@henriwestraIf you compare the steps between what I authored and you replicated, there are differences. It is not an exact replica and it is difficult to point out the error from this screenshot.
Can you please share the M that is giving you this error. Then I can compare.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
98 | |
77 | |
66 | |
54 |
User | Count |
---|---|
144 | |
104 | |
100 | |
86 | |
64 |