Forum Discussion
Pageviews into Source|Destination|Count by Session
Hi -
Yes, you can sort on multiple columns. Just select the first column you want to sort on, sort it, and then select the subsequent column you want to have sorted and sort on that one. It won't "unsort" the first colum.
To achieve step 2, here is a good example of how to do that without code:
Basically, after sorting you create an index, and then a second column that is one greater than the index. Then you merge the tables using the index and second index column as the keys.
After doing this, you should have step 2. The rest can be done in regular DAX (or a pivot table) as a measure of the frequence of each occurrence of each unique row. Alternatively, you can use Transform... Group By (with Count as the summary operation) if you really need to have it in the table. I have included this as part of the script below.
Here is an example you can paste into the "Advanced Editor" and walk through one step at a time:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fY9BDoAwCAS/Yno2KQUpKTdr4idqf+H/I2rsyfZGZjYslOKCmx1ED+QRkCYk5ajEx2l8dXX+TYgGMZr7nm66DXw0uvc8K8lzQbeBdYHWgDYFah6SIn8/5F5CFIYbkgK+N9YL", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [SessionID = _t, TimeStamp = _t, PageName = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"SessionID", Int64.Type}, {"TimeStamp", type text}, {"PageName", type text}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
#"Inserted Addition" = Table.AddColumn(#"Added Index", "Addition", each [Index] + 1, type number),
#"Merged Queries" = Table.NestedJoin(#"Inserted Addition", {"Index"}, #"Inserted Addition", {"Addition"}, "Inserted Addition", JoinKind.LeftOuter),
#"Expanded Inserted Addition" = Table.ExpandTableColumn(#"Merged Queries", "Inserted Addition", {"PageName"}, {"Inserted Addition.PageName"}),
#"Grouped Rows" = Table.Group(#"Expanded Inserted Addition", {"PageName", "Inserted Addition.PageName"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
#"Reordered Columns" = Table.ReorderColumns(#"Grouped Rows",{"Inserted Addition.PageName", "PageName", "Count"})
in
#"Reordered Columns"
Hope this helps,
Peter