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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
basrooz
Advocate I
Advocate I

Google Analytics Connector : editing the data in Microsoft M

Hi,

I'm using the Google Analytics connector to pull some data from Google Analytics. In Microsoft M the code looks like this:

 

let
    Source = GoogleAnalytics.Accounts(),
    #"xxxxxx" = Source{[Id="xxxxxx"]}[Data],
    #"UA-xxxxxxx-5" = #"xxxxxxxx"{[Id="UA-xxxxxxxx-5"]}[Data],
    #"xxxxxxxx" = #"UA-xxxxxxxxx-5"{[Id="xxxxxxxxx"]}[Data],
    #"Added Items" = Cube.Transform(#"xxxxxxxxx",
        {
            {Cube.AddAndExpandDimensionColumn, "ga:date", {"ga:date"}, {"Date"}},            
            {Cube.AddAndExpandDimensionColumn, "ga:hostname", {"ga:hostname"}, {"Culture"}},
            {Cube.AddAndExpandDimensionColumn, "ga:pagePath", {"ga:pagePath"}, {"Page"}},
            {Cube.AddMeasureColumn, "Users", "ga:users"}
        })
in
    #"Added Items"

 

I can use PowerQuery to continue filtering the data. For instance, if I want to filter the pagePath to only show me pages with /registration/ in their name, then I can adjust the query as follows:

 

let
    Source = GoogleAnalytics.Accounts(),
    #"xxxxxx" = Source{[Id="xxxxxx"]}[Data],
    #"UA-xxxxxxx-5" = #"xxxxxxxx"{[Id="UA-xxxxxxxx-5"]}[Data],
    #"xxxxxxxx" = #"UA-xxxxxxxxx-5"{[Id="xxxxxxxxx"]}[Data],
    #"Added Items" = Cube.Transform(#"xxxxxxxxx",
        {
            {Cube.AddAndExpandDimensionColumn, "ga:date", {"ga:date"}, {"Date"}},            
            {Cube.AddAndExpandDimensionColumn, "ga:hostname", {"ga:hostname"}, {"Culture"}},
            {Cube.AddAndExpandDimensionColumn, "ga:pagePath", {"ga:pagePath"}, {"Page"}},
            {Cube.AddMeasureColumn, "Users", "ga:users"}
        }),
    #"Filtered Rows" = Table.SelectRows(#"Added Items", each Text.Contains([Page], "/registration/"))
in
    #"Filtered Rows"

 

This is then showing me the amount of unique users, split by every page that has /registration/  in it.

I however do not want to see this for every page that has /registration/  in it. I want to see it for all pages combined. And as we're talking about unique users, I cannot just pull these numbers like this and sum it up, as there will be loads of duplicates in there.

 

Is it therefore possible to already filter the Google Analytics pages at the start of the query? As that way it would show me the total amount of unique users for all pages that have /registration/  in it. Something like this (I don't know how to program this so this is really just an example):

 

let
    Source = GoogleAnalytics.Accounts(),
    #"xxxxxx" = Source{[Id="xxxxxx"]}[Data],
    #"UA-xxxxxxx-5" = #"xxxxxxxx"{[Id="UA-xxxxxxxx-5"]}[Data],
    #"xxxxxxxx" = #"UA-xxxxxxxxx-5"{[Id="xxxxxxxxx"]}[Data],
    #"Added Items" = Cube.Transform(#"xxxxxxxxx",
        {
            {Cube.AddAndExpandDimensionColumn, "ga:date", {"ga:date"}, {"Date"}},            
            {Cube.AddAndExpandDimensionColumn, "ga:hostname", {"ga:hostname"}, {"Culture"}},
            {Cube.AddAndExpandDimensionColumn, "ga:pagePath", {"ga:pagePath"}, where ga:pagePath = /registration/ , {"Page"}}

,
            {Cube.AddMeasureColumn, "Users", "ga:users"}
        })
in
    #"Added Items"

 

Keen to hear your thoughts!
Best regards

Bas

1 ACCEPTED SOLUTION
V-pazhen-msft
Community Support
Community Support

@basrooz 

I doubt this is possible. For those online service connectors, you cannot filter before importing, tGA does not have something like advanced option to use SQL statement for SQL Server.

 

You may add filter in the code but I guess it is not what you are looking for. Check the replies:

powerbi - Apply filters to Google Analytics query URI in Power BI - Stack Overflow

 

 

Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
V-pazhen-msft
Community Support
Community Support

@basrooz 

I doubt this is possible. For those online service connectors, you cannot filter before importing, tGA does not have something like advanced option to use SQL statement for SQL Server.

 

You may add filter in the code but I guess it is not what you are looking for. Check the replies:

powerbi - Apply filters to Google Analytics query URI in Power BI - Stack Overflow

 

 

Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

@V-pazhen-msft Thanks for your reply. I was afraid that was the case as I have Googled for quite a while but haven't managed to find a solution. I guess the best way would be to move all the Google Analytics data into Bigquery and query it from there.

 

Thanks!

Hi @basrooz were you able to find a solution? As a workaround,maybe you can try to test your connection with a 3rd party connector. I currently use windsor.ai 's GA connector and I can filter my data on a 'preview' step by date range, fields or accounts, before exporting to PBI, and without using any messy M code or any SQL query. In case you wonder, to make the connection first search for the GA connector in the data sources list:

 

GA-1.png

 

After that, just grant access to your GA account using your credentials, then on preview and destination page you will see a preview of your GA fields:

 

GA-2.png

 

There just select the fields you need. Finally, just select PBI as your data destination and finally just copy and paste the url on PBI --> Get Data --> Web --> Paste the url.

 

SELECT_DESTINATION_NEW.png

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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