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

Get Fabric certified for FREE! Don't miss your chance! Learn more

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
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.