Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Indexing Unique Events

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

 

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@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"

Regards
Zubair

Please try my custom visuals

View solution in original post

1 REPLY 1
Zubair_Muhammad
Community Champion
Community Champion

@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"

Regards
Zubair

Please try my custom visuals

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.