AWQL Query based on multiple date ranges









up vote
0
down vote

favorite












I'm pulling some simple stats from the AdWords API and I want to enhance it to bring back YoY data.



I want to get total clicks, impressions, ctr for a month in 2017 and 2018.



My Goal: pull this data in 1 call...I don't want to have to call the API twice every time I need to compare 2 date ranges.



I'm not certain AWQL can cater for this though. Can anyone advise? Here's my code...



var googleService = adClient.GetService(Services.V0.GoogleAdsService);

string query = @"SELECT date, metrics.impressions, metrics.clicks, metrics.ctr
FROM campaign
WHERE date BETWEEN '2018-10-01' AND '2018-10-31'
OR date BETWEEN '2017-10-01' AND '2017-10-31' // <- this bit is not working
LIMIT 50";

PagedEnumerable<SearchGoogleAdsResponse, GoogleAdsRow> response =
googleService.Search(customerId.ToString(), query);


if(response!=null && response.Count()>0)

//then (just as an example), I could extract my info like...

long clicks2018 = Convert.ToInt64(response.Where(n => n.Date.StartsWith("2018")).Sum(n => n.Metrics.Clicks));
long impressions2018 = Convert.ToInt64(response.Where(n => n.Date.StartsWith("2018")).Sum(n => n.Metrics.Impressions));
double ctr2018 = Convert.ToDouble(response.Where(n => n.Date.StartsWith("2018")).Sum(n => n.Metrics.Ctr));

long clicks2017 = Convert.ToInt64(response.Where(n=>n.Date.StartsWith("2017")).Sum(n => n.Metrics.Clicks));
long impressions2017 = Convert.ToInt64(response.Where(n => n.Date.StartsWith("2017")).Sum(n => n.Metrics.Impressions));
double ctr2017 = Convert.ToDouble(response.Where(n => n.Date.StartsWith("2017")).Sum(n => n.Metrics.Ctr));











share|improve this question



























    up vote
    0
    down vote

    favorite












    I'm pulling some simple stats from the AdWords API and I want to enhance it to bring back YoY data.



    I want to get total clicks, impressions, ctr for a month in 2017 and 2018.



    My Goal: pull this data in 1 call...I don't want to have to call the API twice every time I need to compare 2 date ranges.



    I'm not certain AWQL can cater for this though. Can anyone advise? Here's my code...



    var googleService = adClient.GetService(Services.V0.GoogleAdsService);

    string query = @"SELECT date, metrics.impressions, metrics.clicks, metrics.ctr
    FROM campaign
    WHERE date BETWEEN '2018-10-01' AND '2018-10-31'
    OR date BETWEEN '2017-10-01' AND '2017-10-31' // <- this bit is not working
    LIMIT 50";

    PagedEnumerable<SearchGoogleAdsResponse, GoogleAdsRow> response =
    googleService.Search(customerId.ToString(), query);


    if(response!=null && response.Count()>0)

    //then (just as an example), I could extract my info like...

    long clicks2018 = Convert.ToInt64(response.Where(n => n.Date.StartsWith("2018")).Sum(n => n.Metrics.Clicks));
    long impressions2018 = Convert.ToInt64(response.Where(n => n.Date.StartsWith("2018")).Sum(n => n.Metrics.Impressions));
    double ctr2018 = Convert.ToDouble(response.Where(n => n.Date.StartsWith("2018")).Sum(n => n.Metrics.Ctr));

    long clicks2017 = Convert.ToInt64(response.Where(n=>n.Date.StartsWith("2017")).Sum(n => n.Metrics.Clicks));
    long impressions2017 = Convert.ToInt64(response.Where(n => n.Date.StartsWith("2017")).Sum(n => n.Metrics.Impressions));
    double ctr2017 = Convert.ToDouble(response.Where(n => n.Date.StartsWith("2017")).Sum(n => n.Metrics.Ctr));











    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm pulling some simple stats from the AdWords API and I want to enhance it to bring back YoY data.



      I want to get total clicks, impressions, ctr for a month in 2017 and 2018.



      My Goal: pull this data in 1 call...I don't want to have to call the API twice every time I need to compare 2 date ranges.



      I'm not certain AWQL can cater for this though. Can anyone advise? Here's my code...



      var googleService = adClient.GetService(Services.V0.GoogleAdsService);

      string query = @"SELECT date, metrics.impressions, metrics.clicks, metrics.ctr
      FROM campaign
      WHERE date BETWEEN '2018-10-01' AND '2018-10-31'
      OR date BETWEEN '2017-10-01' AND '2017-10-31' // <- this bit is not working
      LIMIT 50";

      PagedEnumerable<SearchGoogleAdsResponse, GoogleAdsRow> response =
      googleService.Search(customerId.ToString(), query);


      if(response!=null && response.Count()>0)

      //then (just as an example), I could extract my info like...

      long clicks2018 = Convert.ToInt64(response.Where(n => n.Date.StartsWith("2018")).Sum(n => n.Metrics.Clicks));
      long impressions2018 = Convert.ToInt64(response.Where(n => n.Date.StartsWith("2018")).Sum(n => n.Metrics.Impressions));
      double ctr2018 = Convert.ToDouble(response.Where(n => n.Date.StartsWith("2018")).Sum(n => n.Metrics.Ctr));

      long clicks2017 = Convert.ToInt64(response.Where(n=>n.Date.StartsWith("2017")).Sum(n => n.Metrics.Clicks));
      long impressions2017 = Convert.ToInt64(response.Where(n => n.Date.StartsWith("2017")).Sum(n => n.Metrics.Impressions));
      double ctr2017 = Convert.ToDouble(response.Where(n => n.Date.StartsWith("2017")).Sum(n => n.Metrics.Ctr));











      share|improve this question















      I'm pulling some simple stats from the AdWords API and I want to enhance it to bring back YoY data.



      I want to get total clicks, impressions, ctr for a month in 2017 and 2018.



      My Goal: pull this data in 1 call...I don't want to have to call the API twice every time I need to compare 2 date ranges.



      I'm not certain AWQL can cater for this though. Can anyone advise? Here's my code...



      var googleService = adClient.GetService(Services.V0.GoogleAdsService);

      string query = @"SELECT date, metrics.impressions, metrics.clicks, metrics.ctr
      FROM campaign
      WHERE date BETWEEN '2018-10-01' AND '2018-10-31'
      OR date BETWEEN '2017-10-01' AND '2017-10-31' // <- this bit is not working
      LIMIT 50";

      PagedEnumerable<SearchGoogleAdsResponse, GoogleAdsRow> response =
      googleService.Search(customerId.ToString(), query);


      if(response!=null && response.Count()>0)

      //then (just as an example), I could extract my info like...

      long clicks2018 = Convert.ToInt64(response.Where(n => n.Date.StartsWith("2018")).Sum(n => n.Metrics.Clicks));
      long impressions2018 = Convert.ToInt64(response.Where(n => n.Date.StartsWith("2018")).Sum(n => n.Metrics.Impressions));
      double ctr2018 = Convert.ToDouble(response.Where(n => n.Date.StartsWith("2018")).Sum(n => n.Metrics.Ctr));

      long clicks2017 = Convert.ToInt64(response.Where(n=>n.Date.StartsWith("2017")).Sum(n => n.Metrics.Clicks));
      long impressions2017 = Convert.ToInt64(response.Where(n => n.Date.StartsWith("2017")).Sum(n => n.Metrics.Impressions));
      double ctr2017 = Convert.ToDouble(response.Where(n => n.Date.StartsWith("2017")).Sum(n => n.Metrics.Ctr));








      c# google-adwords adwords-api-v201109 awql






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 days ago

























      asked 2 days ago









      scgough

      2,69911033




      2,69911033



























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53225039%2fawql-query-based-on-multiple-date-ranges%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53225039%2fawql-query-based-on-multiple-date-ranges%23new-answer', 'question_page');

          );

          Post as a guest














































































          Popular posts from this blog

          Kleinkühnau

          Makov (Slowakei)

          Deutsches Schauspielhaus