<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Matt Lee</title>
    <description>The latest articles on DEV Community by Matt Lee (@matt_lee_8e6b269551323b60).</description>
    <link>https://dev.to/matt_lee_8e6b269551323b60</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4177762%2F7c38dd1e-9d87-452f-92ff-62d29e73d175.png</url>
      <title>DEV Community: Matt Lee</title>
      <link>https://dev.to/matt_lee_8e6b269551323b60</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/matt_lee_8e6b269551323b60"/>
    <language>en</language>
    <item>
      <title>Ranking every Texas bar by alcohol sales with one SoQL query</title>
      <dc:creator>Matt Lee</dc:creator>
      <pubDate>Sun, 11 Oct 2026 20:15:48 +0000</pubDate>
      <link>https://dev.to/matt_lee_8e6b269551323b60/ranking-every-texas-bar-by-alcohol-sales-with-one-soql-query-51io</link>
      <guid>https://dev.to/matt_lee_8e6b269551323b60/ranking-every-texas-bar-by-alcohol-sales-with-one-soql-query-51io</guid>
      <description>&lt;p&gt;Texas requires every mixed-beverage permit holder to report monthly liquor, wine, beer and cover-charge receipts. The Comptroller publishes all of it on data.texas.gov (dataset &lt;code&gt;naix-2893&lt;/code&gt;). That's millions of rows going back years, one row per location per month.&lt;/p&gt;

&lt;p&gt;The raw data answers "what did venue X report in March?" What people actually want to know is "who are the biggest and fastest-growing venues in my market, and who just opened?" Here's how to get that without downloading the dataset.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trailing 12 months + prior 12 months in one query
&lt;/h2&gt;

&lt;p&gt;SoQL supports &lt;code&gt;case()&lt;/code&gt; inside aggregates, so you can compute several windows in one grouped pass:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="k"&gt;select&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;taxpayer_number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;location_number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="k"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;location_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;v_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;location_city&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;v_city&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="k"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;case&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;obligation_end_date_yyyymmdd&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'2025-08-31'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;total_receipts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;t12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="k"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;case&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;obligation_end_date_yyyymmdd&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="s1"&gt;'2025-08-31'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;total_receipts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;p12&lt;/span&gt;
&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="k"&gt;where&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;obligation_end_date_yyyymmdd&lt;/span&gt; &lt;span class="k"&gt;between&lt;/span&gt; &lt;span class="s1"&gt;'2024-09-30'&lt;/span&gt; &lt;span class="k"&gt;and&lt;/span&gt; &lt;span class="s1"&gt;'2026-08-31'&lt;/span&gt;
&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="k"&gt;group&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;taxpayer_number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;location_number&lt;/span&gt;
&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="k"&gt;order&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;t12&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;YoY is just &lt;code&gt;t12 / p12 - 1&lt;/code&gt;. A venue with &lt;code&gt;p12 = 0&lt;/code&gt; and recent first months is "new". One with zero receipts in the latest three months is "possibly closed".&lt;/p&gt;

&lt;h2&gt;
  
  
  Gotcha 1: alias collisions
&lt;/h2&gt;

&lt;p&gt;If you write &lt;code&gt;max(location_name) as location_name&lt;/code&gt; and later filter &lt;code&gt;$where=location_name like ...&lt;/code&gt;, Socrata reads the alias as an aggregate in an ungrouped context and fails. Prefix your aliases (&lt;code&gt;v_name&lt;/code&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Gotcha 2: the newest month is partial
&lt;/h2&gt;

&lt;p&gt;Filers report late, so the latest month on the portal is usually incomplete. I pick the newest month whose row count is at least 90% of the busiest of the last six months.&lt;/p&gt;

&lt;h2&gt;
  
  
  Results (Sep 2025 – Aug 2026)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Houston $1.57B, Dallas $1.22B, Austin $1.16B, San Antonio $0.83B, Fort Worth $0.46B&lt;/li&gt;
&lt;li&gt;Largest single venue: AT&amp;amp;T Stadium (Arlington), $38.3M&lt;/li&gt;
&lt;li&gt;Lubbock's #1: United Supermarkets Arena, $7.8M&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Packaged version
&lt;/h2&gt;

&lt;p&gt;I wrapped this (plus city ranks, new-venue and closed-venue flags, and a raw monthly mode) as an Apify Actor so non-developers can run it from a form or schedule it: &lt;a href="https://apify.com/lonestar-leads/texas-bar-restaurant-sales" rel="noopener noreferrer"&gt;https://apify.com/lonestar-leads/texas-bar-restaurant-sales&lt;/a&gt;. A companion Actor tracks new Texas businesses daily, including new LLCs: &lt;a href="https://apify.com/lonestar-leads/texas-new-business-leads" rel="noopener noreferrer"&gt;https://apify.com/lonestar-leads/texas-new-business-leads&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Data: Texas Comptroller of Public Accounts via data.texas.gov. Figures are gross receipts as reported, not profit.&lt;/p&gt;

</description>
      <category>opendata</category>
      <category>javascript</category>
      <category>datascience</category>
      <category>apify</category>
    </item>
  </channel>
</rss>
