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

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.

Reply
Anonymous
Not applicable

Pageviews into Source|Destination|Count by Session

Hello there.

I've been able to do it on paper - but I'm really struggling in PowerQuery. Every row in my data is a PageView on a website. A single session can have one or more pageviews (rows). I need to get my data into the below format as shown by "3". I don't know where to start (even in step 1 -- how do I sort by multiple columns as if I were in excel). Could someone please help me? I know its a big ask, but I've tried my best to make it easy to see my problem. 

michelleAA_0-1679148888611.png

 

Table of Pageviews ("1" in above)

SessionID    Timestamp        PageName

106/03/2023 23:56:35Pg.A
106/03/2023 23:57:17Pg.B
106/03/2023 23:57:31Pg.C
106/03/2023 23:57:36Pg.F
106/03/2023 23:55:37Pg.B
106/03/2023 23:55:40Pg.C
213/03/2023 09:25:35Pg.B
213/03/2023 09:27:00Pg.C
213/03/2023 09:29:02Pg.F

Thanks in advance,
Michelle

 

 

1 REPLY 1
Peter_Beck
Resolver II
Resolver II

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:

 

https://exceltown.com/en/tutorials/power-bi/powerbi-com-and-power-bi-desktop/power-bi-data-sources/p...

 

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.

Top Solution Authors
Top Kudoed Authors