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.
Hello everyone!
I would like to create an index column addressing unique events. But up to now I couldn't manage to do it in Power BI.
The index column should look like this based on when the Column A is equal to one:
DateTime Column A Index
01.01.2019 03:00:00 1 1
01.01.2019 04:00:00 1 1
01.01.2019 05:00:00 0
01.01.2019 06:00:00 0
01.01.2019 07:00:00 1 2
01.01.2019 08:00:00 1 2
01.01.2019 09:00:00 0
01.01.2019 10:00:00 0
01.01.2019 11:00:00 1 3
01.01.2019 12:00:00 1 3
01.01.2019 13:00:00 1 3
01.01.2019 14:00:00 1 3
.
.
.
Thanks in advance
Solved! Go to Solution.
@Anonymous
Here is a Power Query Solution
Please see attached file as well
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDUBSJDSwVjKwMDJR0lQ6VYHSRRE6yiphBRA1RRM6yi5lhNsMAqaonVBEMD7MKGWM0wNMIujN1/hggPxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [DateTime = _t, #"Column A" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"DateTime", type datetime}, {"Column A", Int64.Type}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"Column A"}, {{"ALL", each _, type table [DateTime=datetime, Column A=number]}},GroupKind.Local), #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1), #"Reordered Columns" = Table.ReorderColumns(#"Added Index",{"Index", "Column A", "ALL"}), #"Filtered Rows" = Table.SelectRows(#"Reordered Columns", each ([Column A] = 1)), #"Added Index1" = Table.AddIndexColumn(#"Filtered Rows", "Index.1", 1, 1), #"Filtered Rows1" = Table.SelectRows(#"Added Index", each ([Column A] = 0)), #"Added Custom" = Table.AddColumn(#"Filtered Rows1", "Index.1", each null), #"Appended Query" = Table.Combine({#"Added Custom", #"Added Index1"}), #"Sorted Rows" = Table.Sort(#"Appended Query",{{"Index", Order.Ascending}}), #"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"Index"}), #"Expanded ALL" = Table.ExpandTableColumn(#"Removed Columns", "ALL", {"DateTime"}, {"DateTime"}), #"Reordered Columns1" = Table.ReorderColumns(#"Expanded ALL",{"DateTime", "Column A", "Index.1"}) in #"Reordered Columns1"
@Anonymous
Here is a Power Query Solution
Please see attached file as well
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDUBSJDSwVjKwMDJR0lQ6VYHSRRE6yiphBRA1RRM6yi5lhNsMAqaonVBEMD7MKGWM0wNMIujN1/hggPxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [DateTime = _t, #"Column A" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"DateTime", type datetime}, {"Column A", Int64.Type}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"Column A"}, {{"ALL", each _, type table [DateTime=datetime, Column A=number]}},GroupKind.Local), #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1), #"Reordered Columns" = Table.ReorderColumns(#"Added Index",{"Index", "Column A", "ALL"}), #"Filtered Rows" = Table.SelectRows(#"Reordered Columns", each ([Column A] = 1)), #"Added Index1" = Table.AddIndexColumn(#"Filtered Rows", "Index.1", 1, 1), #"Filtered Rows1" = Table.SelectRows(#"Added Index", each ([Column A] = 0)), #"Added Custom" = Table.AddColumn(#"Filtered Rows1", "Index.1", each null), #"Appended Query" = Table.Combine({#"Added Custom", #"Added Index1"}), #"Sorted Rows" = Table.Sort(#"Appended Query",{{"Index", Order.Ascending}}), #"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"Index"}), #"Expanded ALL" = Table.ExpandTableColumn(#"Removed Columns", "ALL", {"DateTime"}, {"DateTime"}), #"Reordered Columns1" = Table.ReorderColumns(#"Expanded ALL",{"DateTime", "Column A", "Index.1"}) in #"Reordered Columns1"
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 | |
99 | |
77 | |
66 | |
54 |
User | Count |
---|---|
144 | |
104 | |
102 | |
87 | |
64 |