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
ai52487963
New Member

Google Analytics query URI in power bi?

I'm querying google analytics from power bi for use with dashboarding and all that. I'm trying to look at page views for a specific page, but power bi likes to bring in all the data first THEN filter. I know the google analytics query URI can be written to filter on just the page I'm interested in, though. I'm wondering: how do I convert my power bi query to make use of that filter?

The power bi query I'm using looks like this:



let
    Source = GoogleAnalytics.Accounts(),
    #"###" = Source{[Id="###"]}[Data],
    #"UA-###-10" = #"###"{[Id="UA-###-10"]}[Data],
    #"#####" = #"UA-###-10"{[Id="#####"]}[Data],
    #"Added Items" = Cube.Transform(#"#####",
        {
            {Cube.AddAndExpandDimensionColumn, "ga: pagePath", {"ga: pagePath"}, {"Page"}},
            {Cube.AddMeasureColumn, "Pageviews", "ga: pageviews"}
        })
in
    #"Added Items"

 

Note that the "ga: pagePath" syntax shouldn't have a space. I put a space in there to keep the text from inserting emoticons in the code.

 

But this gives me *all* pages, I only want a specific one.

 

The google analytics URI query looks like:

 

https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A###&start-date=30daysAgo&end-date=yesterday...

 

This gives me the correct result since it's doing the filtering for the site that I want at the query level.

Any ideas on how to get the `&filters=...` part at the end of the URI to work correctly in the power bi query?

1 ACCEPTED SOLUTION
v-yuezhe-msft
Employee
Employee

@ai52487963,

When connecting to GA data in Power BI Desktop, bring the date attribute into the query as shown in the following screenshots.
1.JPG2.JPG

Then you can add the following code in the Advanced of your query to filter date between last 30 days and yesterday.

  #"Filtered Rows" = Table.SelectRows(#"Added Items", each [Date] >= Date.AddDays(DateTime.Date(DateTime.LocalNow()),-30) and [Date] <= Date.AddDays(DateTime.Date(DateTime.LocalNow()),-1))  
in
  #"Filtered Rows"

3.JPG

Regards,
Lydia

Community Support Team _ Lydia Zhang
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

1 REPLY 1
v-yuezhe-msft
Employee
Employee

@ai52487963,

When connecting to GA data in Power BI Desktop, bring the date attribute into the query as shown in the following screenshots.
1.JPG2.JPG

Then you can add the following code in the Advanced of your query to filter date between last 30 days and yesterday.

  #"Filtered Rows" = Table.SelectRows(#"Added Items", each [Date] >= Date.AddDays(DateTime.Date(DateTime.LocalNow()),-30) and [Date] <= Date.AddDays(DateTime.Date(DateTime.LocalNow()),-1))  
in
  #"Filtered Rows"

3.JPG

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.