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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Giuseppe89
Frequent Visitor

Retrieve data from Google Analytics by calculating a dimension

Hi all,

 

In PowerBI Desktop I would like to retrieve some web traffic data from Google Analytics (GA4).

The data I need have the following structure:

YearMonthCategoryTotalUsers
202401A10
202401B7
202402A9

where the dimension Category is calculated from the GA dimension page path, more precisely: if the user's page path contains the substring category_a, then Category = A (the same for the category B).

 

In order to retrieve these data I have tried the GA connector, but it does not seem possibile to calculate the dimension Category querying directily Google Analytics.

 

Does anyone have any ideas to solve the issue?

Is it possible to retrieve GA4 data using the PowerBI connector WEB (executing some GET/POST calls) and defining the field I need?

 

Note:

  • I don't want to load all GA4 data in PowerBI because I have >10M data

 

Thanks in advance

1 ACCEPTED SOLUTION
v-zhengdxu-msft
Community Support
Community Support

Hi @Giuseppe89 

 

If you don't want to import your data. 
You can use the REST API in Power Query, which is a viable way to do it at the moment:

Google Analytics Data API  |  Google for Developers

You can use the API to get data from data source and write mcode to get the output data you want.

Here is a sample for your reference, and this code needs to be modified:

 

let
    Source = Web.Page(Web.Contents("YOUR_API_ENDPOINT", [Headers=[Authorization="Bearer YOUR_ACCESS_TOKEN"]])),
    Data = Source{0}[content],
    JsonData = Json.Document(Data),
    #"Converted to Table" = Record.ToTable(JsonData),
    #"Added Custom" = Table.AddColumn(#"Converted to Table", "Category", each if Text.Contains([PagePath], "category_a") then "A" else if Text.Contains([PagePath], "category_b") then "B" else "Other"),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"YearMonth", "Category"}, {{"TotalUsers", each List.Sum([Users]), type number}})
in
    #"Grouped Rows"

 

Here for your reference:

javascript - Google Analytics Reporting API V4, User does not have sufficient permissions for this p...

The above is an implementation that requires you to have a deep understanding of Power Query M code and understand the relevant knowledge of API.

 

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
ReportGuru
Post Patron
Post Patron

Hi @Giuseppe89 as a workaround, maybe you can try to test your connection with a 3rd party tool, which pulls data directly from the API and would not require any coding on your side. I've tried windsor.ai, supemetrics and funnel.io. I stayed with windsor because it is much cheaper so just to let you know other options. In case you wonder, to make the connection first search for the GA4 connector in the data sources list:

 

GA4-1.png

 

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

 

GA4-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

 

v-zhengdxu-msft
Community Support
Community Support

Hi @Giuseppe89 

 

If you don't want to import your data. 
You can use the REST API in Power Query, which is a viable way to do it at the moment:

Google Analytics Data API  |  Google for Developers

You can use the API to get data from data source and write mcode to get the output data you want.

Here is a sample for your reference, and this code needs to be modified:

 

let
    Source = Web.Page(Web.Contents("YOUR_API_ENDPOINT", [Headers=[Authorization="Bearer YOUR_ACCESS_TOKEN"]])),
    Data = Source{0}[content],
    JsonData = Json.Document(Data),
    #"Converted to Table" = Record.ToTable(JsonData),
    #"Added Custom" = Table.AddColumn(#"Converted to Table", "Category", each if Text.Contains([PagePath], "category_a") then "A" else if Text.Contains([PagePath], "category_b") then "B" else "Other"),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"YearMonth", "Category"}, {{"TotalUsers", each List.Sum([Users]), type number}})
in
    #"Grouped Rows"

 

Here for your reference:

javascript - Google Analytics Reporting API V4, User does not have sufficient permissions for this p...

The above is an implementation that requires you to have a deep understanding of Power Query M code and understand the relevant knowledge of API.

 

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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