Forum Discussion

lipesouza12's avatar
lipesouza12
Frequent Visitor
4 years ago
Solved

Relative Count If M Language WITHOUT Groupig

Hello everybody, I have a question that may have a simple answer but I don't see it. I need an indexer that identifies how many times a given row repeats. Working exactly like rexcel's relative COU...
  • Vijay_A_Verma's avatar
    4 years ago

    See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately)

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUQoxMjAHUgZGeoZKsTroYkZgMScUMWMs6ojVawRXZ2hgCNcaCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"COND. 1" = _t, #"COND. 2" = _t, #"COND. 3" = _t]),
        #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
        #"Grouped Rows" = Table.Group(#"Added Index", {"COND. 2", "COND. 3"}, {{"Temp", each _, type table [COND. 1=nullable text, COND. 2=nullable text, COND. 3=nullable text]}}),
        #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Temp], "COUNT IF", 1, 1, Int64.Type)),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Temp"}),
        #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"COND. 1", "COUNT IF", "Index"}, {"COND. 1", "COUNT IF", "Index"}),
        #"Sorted Rows" = Table.Sort(#"Expanded Custom",{{"Index", Order.Ascending}}),
        #"Removed Columns1" = Table.RemoveColumns(#"Sorted Rows",{"Index"}),
        #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns1",{"COND. 1", "COND. 2", "COND. 3", "COUNT IF"})
    in
        #"Reordered Columns"