<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How much USD are you spending on Databricks? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-much-usd-are-you-spending-on-databricks/m-p/67346#M33324</link>
    <description>&lt;P&gt;Join two system tables and get exactly how much USD you are spending.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The short version of the query:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SELECT 
    u.usage_date,
    u.sku_name,
    SUM(u.usage_quantity * p.pricing.default) AS total_spent,
    p.currency_code
FROM 
    system.billing.usage u
LEFT JOIN 
    system.billing.list_prices p
ON 
    u.sku_name = p.sku_name
    AND u.cloud = p.cloud
    AND u.usage_start_time &amp;lt; COALESCE(p.price_end_time, date'2029-12-31')
    AND u.usage_end_time &amp;gt; p.price_start_time
GROUP BY 
    ALL
ORDER BY 
    ALL;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Extended version (which is handling potential price overlap):&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SELECT 
    u.usage_date,
    u.sku_name,
    SUM(
        (UNIX_TIMESTAMP(
            LEAST(u.usage_end_time, COALESCE(p.price_end_time, date'2029-12-31'))
        ) -
        UNIX_TIMESTAMP(
            GREATEST(u.usage_start_time, p.price_start_time)
        ))
        / (UNIX_TIMESTAMP(u.usage_end_time) - UNIX_TIMESTAMP(u.usage_start_time))
        * u.usage_quantity * p.pricing.default
    ) AS total_spent,
    p.currency_code
FROM 
    system.billing.usage u
LEFT JOIN 
    system.billing.list_prices p
ON 
    u.sku_name = p.sku_name
    AND u.cloud = p.cloud
    AND u.usage_start_time &amp;lt; COALESCE(p.price_end_time, date'2029-12-31')
    AND u.usage_end_time &amp;gt; p.price_start_time
GROUP BY 
    ALL
ORDER BY 
    ALL;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="system_pig.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/7260i5CDEAC896FBBB3A0/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999" role="button" title="system_pig.png" alt="system_pig.png" /&gt;&lt;/span&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 25 Apr 2024 19:20:08 GMT</pubDate>
    <dc:creator>Hubert-Dudek</dc:creator>
    <dc:date>2024-04-25T19:20:08Z</dc:date>
    <item>
      <title>How much USD are you spending on Databricks?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-much-usd-are-you-spending-on-databricks/m-p/67346#M33324</link>
      <description>&lt;P&gt;Join two system tables and get exactly how much USD you are spending.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The short version of the query:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SELECT 
    u.usage_date,
    u.sku_name,
    SUM(u.usage_quantity * p.pricing.default) AS total_spent,
    p.currency_code
FROM 
    system.billing.usage u
LEFT JOIN 
    system.billing.list_prices p
ON 
    u.sku_name = p.sku_name
    AND u.cloud = p.cloud
    AND u.usage_start_time &amp;lt; COALESCE(p.price_end_time, date'2029-12-31')
    AND u.usage_end_time &amp;gt; p.price_start_time
GROUP BY 
    ALL
ORDER BY 
    ALL;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Extended version (which is handling potential price overlap):&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SELECT 
    u.usage_date,
    u.sku_name,
    SUM(
        (UNIX_TIMESTAMP(
            LEAST(u.usage_end_time, COALESCE(p.price_end_time, date'2029-12-31'))
        ) -
        UNIX_TIMESTAMP(
            GREATEST(u.usage_start_time, p.price_start_time)
        ))
        / (UNIX_TIMESTAMP(u.usage_end_time) - UNIX_TIMESTAMP(u.usage_start_time))
        * u.usage_quantity * p.pricing.default
    ) AS total_spent,
    p.currency_code
FROM 
    system.billing.usage u
LEFT JOIN 
    system.billing.list_prices p
ON 
    u.sku_name = p.sku_name
    AND u.cloud = p.cloud
    AND u.usage_start_time &amp;lt; COALESCE(p.price_end_time, date'2029-12-31')
    AND u.usage_end_time &amp;gt; p.price_start_time
GROUP BY 
    ALL
ORDER BY 
    ALL;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="system_pig.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/7260i5CDEAC896FBBB3A0/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999" role="button" title="system_pig.png" alt="system_pig.png" /&gt;&lt;/span&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2024 19:20:08 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-much-usd-are-you-spending-on-databricks/m-p/67346#M33324</guid>
      <dc:creator>Hubert-Dudek</dc:creator>
      <dc:date>2024-04-25T19:20:08Z</dc:date>
    </item>
    <item>
      <title>Re: How much USD are you spending on Databricks?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-much-usd-are-you-spending-on-databricks/m-p/67625#M33390</link>
      <description>&lt;P&gt;Thank you for sharing this information&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/25346"&gt;@Hubert-Dudek&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2024 21:56:26 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-much-usd-are-you-spending-on-databricks/m-p/67625#M33390</guid>
      <dc:creator>jose_gonzalez</dc:creator>
      <dc:date>2024-04-29T21:56:26Z</dc:date>
    </item>
  </channel>
</rss>

