<?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 Re: Genie generates MEASURE expression with &amp;quot;filter&amp;quot; clause in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/genie-generates-measure-expression-with-quot-filter-quot-clause/m-p/149171#M53028</link>
    <description>&lt;P&gt;Hi &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/9268"&gt;@Malthe&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;This does appear to be a hallucination. I would recommend you submit a support ticket if possible, so this gets correctly documented for the product team.&lt;/P&gt;
&lt;P&gt;As for how to defend against it, my recommendation is to invest in Metadata and Configuration. Metadata as a part of the metrics can define things like "deviceCount is defined with the filter "Where isACTIVE = TRUE."&lt;/P&gt;
&lt;P&gt;From a configuration/instructions perspective, you can add instructions and sample queries to the Genie space to mitigate this. Using the combination of sample queries, instructions, and benchmarks (&lt;A href="https://learn.microsoft.com/en-us/azure/databricks/genie/knowledge-store#what-is-a-knowledge-store" target="_self"&gt;see Knowledge Store&lt;/A&gt;) you can curate a Genie space's behavior to account for this until we improve the capability.&lt;/P&gt;
&lt;P&gt;I see tons of investment in this space and Metric Views are still relatively new. I have faith this will be fixed soon.&lt;/P&gt;</description>
    <pubDate>Tue, 24 Feb 2026 13:47:27 GMT</pubDate>
    <dc:creator>Commitchell</dc:creator>
    <dc:date>2026-02-24T13:47:27Z</dc:date>
    <item>
      <title>Genie generates MEASURE expression with "filter" clause</title>
      <link>https://community.databricks.com/t5/data-engineering/genie-generates-measure-expression-with-quot-filter-quot-clause/m-p/148884#M52987</link>
      <description>&lt;P&gt;Genie generated a query against a metric view that introduces a "filter" clause as a second parameter to MEASURE:&lt;/P&gt;&lt;LI-CODE lang="java"&gt;SELECT
  `countryName`,
  MEASURE(`deviceCount`, `isActive` = true) AS `online`,
  MEASURE(`deviceCount`, `isActive` = false) AS `offline`
FROM
  `dev`.`test`.`my_metric_view`
GROUP BY
  ALL
WITH ROLLUP&lt;/LI-CODE&gt;&lt;P&gt;Is that a hallucination or an indication that filtering measures will become a feature in a future release?&lt;/P&gt;&lt;P&gt;If it's the former, how are we supposed to defend against such a hallucination?&lt;/P&gt;</description>
      <pubDate>Fri, 20 Feb 2026 10:05:24 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/genie-generates-measure-expression-with-quot-filter-quot-clause/m-p/148884#M52987</guid>
      <dc:creator>Malthe</dc:creator>
      <dc:date>2026-02-20T10:05:24Z</dc:date>
    </item>
    <item>
      <title>Re: Genie generates MEASURE expression with "filter" clause</title>
      <link>https://community.databricks.com/t5/data-engineering/genie-generates-measure-expression-with-quot-filter-quot-clause/m-p/148970#M52999</link>
      <description>&lt;P&gt;Note that sometimes, Genie also generates FILTER expressions:&lt;/P&gt;&lt;LI-CODE lang="java"&gt;SELECT MEASURE(`deviceCount`) FILTER(WHERE `isActive` = TRUE)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;It seems that the underlying model is unable to accurately grasp the grammar around the MEASURE function.&lt;/P&gt;</description>
      <pubDate>Sun, 22 Feb 2026 08:04:58 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/genie-generates-measure-expression-with-quot-filter-quot-clause/m-p/148970#M52999</guid>
      <dc:creator>Malthe</dc:creator>
      <dc:date>2026-02-22T08:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: Genie generates MEASURE expression with "filter" clause</title>
      <link>https://community.databricks.com/t5/data-engineering/genie-generates-measure-expression-with-quot-filter-quot-clause/m-p/149171#M53028</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/9268"&gt;@Malthe&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;This does appear to be a hallucination. I would recommend you submit a support ticket if possible, so this gets correctly documented for the product team.&lt;/P&gt;
&lt;P&gt;As for how to defend against it, my recommendation is to invest in Metadata and Configuration. Metadata as a part of the metrics can define things like "deviceCount is defined with the filter "Where isACTIVE = TRUE."&lt;/P&gt;
&lt;P&gt;From a configuration/instructions perspective, you can add instructions and sample queries to the Genie space to mitigate this. Using the combination of sample queries, instructions, and benchmarks (&lt;A href="https://learn.microsoft.com/en-us/azure/databricks/genie/knowledge-store#what-is-a-knowledge-store" target="_self"&gt;see Knowledge Store&lt;/A&gt;) you can curate a Genie space's behavior to account for this until we improve the capability.&lt;/P&gt;
&lt;P&gt;I see tons of investment in this space and Metric Views are still relatively new. I have faith this will be fixed soon.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Feb 2026 13:47:27 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/genie-generates-measure-expression-with-quot-filter-quot-clause/m-p/149171#M53028</guid>
      <dc:creator>Commitchell</dc:creator>
      <dc:date>2026-02-24T13:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: Genie generates MEASURE expression with "filter" clause</title>
      <link>https://community.databricks.com/t5/data-engineering/genie-generates-measure-expression-with-quot-filter-quot-clause/m-p/149179#M53030</link>
      <description>&lt;P&gt;I'm unable to file a support issue currently, but I wouldn't expect that I had to instruct the Genie to craft correct queries, syntactically ...&lt;/P&gt;</description>
      <pubDate>Tue, 24 Feb 2026 14:00:14 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/genie-generates-measure-expression-with-quot-filter-quot-clause/m-p/149179#M53030</guid>
      <dc:creator>Malthe</dc:creator>
      <dc:date>2026-02-24T14:00:14Z</dc:date>
    </item>
    <item>
      <title>Re: Genie generates MEASURE expression with "filter" clause</title>
      <link>https://community.databricks.com/t5/data-engineering/genie-generates-measure-expression-with-quot-filter-quot-clause/m-p/149181#M53031</link>
      <description>&lt;P&gt;I agree that'd be nice, and I believe we'll get there. These tools are improving daily.&lt;BR /&gt;&lt;BR /&gt;However, despite the cute name "Genie," this technology is not magic. LLMs are non-deterministic. I'm obviously bias, but Databricks provides the most robust capabilities to curate these models to be more consistent, reliable, cost-effective, and trustworthy. Sometimes that means you have to provide metadata, examples, or instructions to augment the model's training.&lt;BR /&gt;&lt;BR /&gt;As you're unable to file a support ticket, I'll make sure to share your experience with the product team directly. We appreciate the feedback!&lt;/P&gt;</description>
      <pubDate>Tue, 24 Feb 2026 14:28:41 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/genie-generates-measure-expression-with-quot-filter-quot-clause/m-p/149181#M53031</guid>
      <dc:creator>Commitchell</dc:creator>
      <dc:date>2026-02-24T14:28:41Z</dc:date>
    </item>
    <item>
      <title>Re: Genie generates MEASURE expression with "filter" clause</title>
      <link>https://community.databricks.com/t5/data-engineering/genie-generates-measure-expression-with-quot-filter-quot-clause/m-p/149259#M53052</link>
      <description>&lt;P&gt;Thanks. I understand it's not magic, but a very trivial improvement would be to validate the generated query before presenting it to the user. If it doesn't validate, then on the Genie side something has to happen and certainly a syntax error should be presented with a caption such as a "Genie is currently unable to form a valid query".&lt;/P&gt;</description>
      <pubDate>Wed, 25 Feb 2026 08:30:32 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/genie-generates-measure-expression-with-quot-filter-quot-clause/m-p/149259#M53052</guid>
      <dc:creator>Malthe</dc:creator>
      <dc:date>2026-02-25T08:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: Genie generates MEASURE expression with "filter" clause</title>
      <link>https://community.databricks.com/t5/data-engineering/genie-generates-measure-expression-with-quot-filter-quot-clause/m-p/149287#M53061</link>
      <description>&lt;P data-unlink="true"&gt;I agree. If you've seen &lt;A href="https://docs.databricks.com/aws/en/genie/agent-mode" target="_self"&gt;Genie "Agent Mode,"&lt;/A&gt; that's exactly how it works. We strive to provide this type of transparency throughout the product experience. Keep the feedback coming!&lt;/P&gt;</description>
      <pubDate>Wed, 25 Feb 2026 12:17:11 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/genie-generates-measure-expression-with-quot-filter-quot-clause/m-p/149287#M53061</guid>
      <dc:creator>Commitchell</dc:creator>
      <dc:date>2026-02-25T12:17:11Z</dc:date>
    </item>
    <item>
      <title>Hi @Malthe, The behavior you are seeing is indeed the LLM...</title>
      <link>https://community.databricks.com/t5/data-engineering/genie-generates-measure-expression-with-quot-filter-quot-clause/m-p/150330#M53366</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/9268"&gt;@Malthe&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;The behavior you are seeing is indeed the LLM generating invalid SQL syntax. The MEASURE() function takes exactly one argument, which is a reference to a measure column defined in a metric view. There is no second "filter" parameter, and MEASURE does not support the FILTER(WHERE ...) clause that standard aggregate functions like SUM or COUNT support.&lt;/P&gt;
&lt;P&gt;So both of these generated forms are syntactically invalid:&lt;/P&gt;
&lt;PRE&gt;MEASURE(`deviceCount`, `isActive` = true)

MEASURE(`deviceCount`) FILTER(WHERE `isActive` = TRUE)&lt;/PRE&gt;
&lt;P&gt;CORRECT SYNTAX&lt;/P&gt;
&lt;P&gt;The MEASURE function signature is simply:&lt;/P&gt;
&lt;PRE&gt;measure( measure_column )&lt;/PRE&gt;
&lt;P&gt;It inherits its aggregation logic entirely from the metric view definition. Documentation reference:&lt;BR /&gt;
&lt;A href="https://learn.microsoft.com/en-us/azure/databricks/sql/language-manual/functions/measure" target="_blank"&gt;https://learn.microsoft.com/en-us/azure/databricks/sql/language-manual/functions/measure&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;HOW TO ACHIEVE FILTERED MEASURES&lt;/P&gt;
&lt;P&gt;The correct approach is to define the filtered aggregation inside the metric view itself. In the YAML definition of a metric view, individual measures can include inline filter expressions. For example:&lt;/P&gt;
&lt;PRE&gt;CREATE OR REPLACE VIEW my_metric_view
(countryName, deviceCount, onlineDeviceCount, offlineDeviceCount)
WITH METRICS
LANGUAGE YAML
AS $$
version: 0.1
source: your_catalog.your_schema.your_table
dimensions:
- name: countryName
  expr: countryName
measures:
- name: deviceCount
  expr: COUNT(deviceId)
- name: onlineDeviceCount
  expr: COUNT(deviceId) filter (where isActive = true)
- name: offlineDeviceCount
  expr: COUNT(deviceId) filter (where isActive = false)
$$;&lt;/PRE&gt;
&lt;P&gt;Then your query would use separate MEASURE calls:&lt;/P&gt;
&lt;PRE&gt;SELECT
`countryName`,
MEASURE(`onlineDeviceCount`) AS `online`,
MEASURE(`offlineDeviceCount`) AS `offline`
FROM `dev`.`test`.`my_metric_view`
GROUP BY ALL
WITH ROLLUP&lt;/PRE&gt;
&lt;P&gt;This is the supported pattern: push the filter logic into the metric view definition as separate named measures, then reference each one with a simple MEASURE() call.&lt;/P&gt;
&lt;P&gt;MITIGATING GENIE SQL GENERATION ISSUES&lt;/P&gt;
&lt;P&gt;To reduce the likelihood of Genie generating invalid syntax against your metric views, you can use several features in the Genie knowledge store:&lt;/P&gt;
&lt;P&gt;1. Sample queries: Add example SQL queries to your Genie space that demonstrate the correct MEASURE() syntax. Genie uses these as reference when generating new queries.&lt;/P&gt;
&lt;P&gt;2. Instructions: Add explicit instructions such as "The MEASURE function accepts only one argument. Never pass a filter condition as a second argument to MEASURE. Never use FILTER(WHERE ...) with MEASURE."&lt;/P&gt;
&lt;P&gt;3. SQL expressions: Define measures, filters, and dimensions in the knowledge store under Configure &amp;gt; Instructions &amp;gt; SQL Expressions. This gives Genie structured definitions for your business metrics.&lt;/P&gt;
&lt;P&gt;4. Separate measures in the metric view: As shown above, define distinct measures for each filtered variant. This makes it straightforward for Genie to reference the correct measure by name.&lt;/P&gt;
&lt;P&gt;Documentation for the knowledge store:&lt;BR /&gt;
&lt;A href="https://learn.microsoft.com/en-us/azure/databricks/genie/knowledge-store" target="_blank"&gt;https://learn.microsoft.com/en-us/azure/databricks/genie/knowledge-store&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;You may also want to look at Genie Agent Mode (currently in Beta), which uses multi-step reasoning and can iteratively refine its queries:&lt;BR /&gt;
&lt;A href="https://learn.microsoft.com/en-us/azure/databricks/genie/agent-mode" target="_blank"&gt;https://learn.microsoft.com/en-us/azure/databricks/genie/agent-mode&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Your point about validating generated SQL before presenting it to users is well taken. The product team continues to invest in improving Genie's accuracy with metric views, and feedback like this is valuable for prioritizing those improvements.&lt;/P&gt;
&lt;P&gt;* This reply used an agent system I built to research and draft this response based on the wide set of documentation I have available and previous memory. I personally review the draft for any obvious issues and for monitoring system reliability and update it when I detect any drift, but there is still a small chance that something is inaccurate, especially if you are experimenting with brand new features.&lt;/P&gt;
&lt;P&gt;If this answer resolves your question, could you mark it as "Accept as Solution"? That helps other users quickly find the correct fix.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Mar 2026 05:46:01 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/genie-generates-measure-expression-with-quot-filter-quot-clause/m-p/150330#M53366</guid>
      <dc:creator>SteveOstrowski</dc:creator>
      <dc:date>2026-03-09T05:46:01Z</dc:date>
    </item>
  </channel>
</rss>

