Skip to content

Users/alison needs copilot/add intermediary measures calculated measures - #2

Open
AlisonNeedsCopilot wants to merge 8 commits into
mainfrom
Users/AlisonNeedsCopilot/add-intermediary-measures-calculated-measures
Open

Users/alison needs copilot/add intermediary measures calculated measures#2
AlisonNeedsCopilot wants to merge 8 commits into
mainfrom
Users/AlisonNeedsCopilot/add-intermediary-measures-calculated-measures

Conversation

@AlisonNeedsCopilot

@AlisonNeedsCopilot AlisonNeedsCopilot commented Feb 9, 2026

Copy link
Copy Markdown
Owner

##Overview
Previously, having predefined measures in a calculated measure would incorrectly generate the query.
Calculated measures using predefined measures without filters would exclude one of the predefined measures in the resulting query. Calculated measures using predefined measures with filters would mangle the query.
The calculated measure with multiple predefined measures would have multiple aggregate expressions; we only matched to one of them during the compilation process, resulting in the other expression getting mangled or omitted.

In this development, we fix this by following this flow:

  • If there is an operator in the calculated measure, check for aggregate expressions in each operand
  • If there is an aggregate expression, add it to a list of intermediary expressions in the summarize; extend does not support operating on multiple aggregates in one expression.
  • Keep a list of existing intermediary expressions in case they are used in later calculated measures
  • Replace the aggregate expressions used in the calculated measure with their corresponding intermediary expressions

##Technical Details
_extract_and_replace_aggregates(): For each aggregate expression within a given expression, add it to the list of intermediary aggregate expressions encountered if it does not already exist in the list. Replace the aggregate expressions in the original expression with their intermediary expressions.

  • _get_projection_or_summarize(): Handle 4 difference cases when adding expressions to the query:
  1. Simple column with an aggregate expression (no operators) --> Add column to project and summarize. Also add expression to the list of existing aggregates in case it appears in a calculated measure later on
  2. Column alias --> Add to extend
  3. Aggregate expressions with operators --> Add to list of intermediary expressions. Add aggregate expression with replaced intermediary expression to extend. Add intermediary expressions to summarize
  4. Simple column reference --> Add to project

##UI Changes
image

Alison Gim added 4 commits February 5, 2026 20:49
This ensures that extend operations (which may reference summarized columns)
are executed after the summarize clause in the generated KQL query.
…d hoc measures

- Add _find_operator_outside_quotes() helper to find operators not inside quoted strings
- Update _escape_and_quote_columns() to recursively escape both sides of operators
- Update _is_number_literal() to match integers and decimals with digits on both sides
- Add tests for:
  - Two quoted measures: "Measure 1" + "Measure 2" -> ["Measure 1"] + ["Measure 2"]
  - Measure with constant: "Measure 1" * 2 -> ["Measure 1"] * 2
  - Measure with operator in name: "Measure 1-2" -> ["Measure 1-2"]
  - _is_number_literal function validation
- Add comprehensive unit tests for new helper functions:
  - TestIsInsideQuotesOrBrackets (10 tests)
  - TestFindMatchingParen (8 tests)
  - TestHasOperatorsOutsideQuotes (8 tests)
  - TestExtractAndReplaceAggregates (10 tests)
  - TestContainsAggregateFunction (10 tests)
- Add comment explaining existing_aggs registration logic
- Apply black formatting
@AlisonNeedsCopilot
AlisonNeedsCopilot changed the base branch from main to Users/AlisonNeedsCopilot/quote-escape-bracket-multiple-ad-hoc-measures-calculated-measures February 9, 2026 22:52
Alison Gim added 4 commits February 10, 2026 01:34
Prevents double-escaping of expressions like (count(a) + count(b)) by
detecting matching outer parentheses, processing the inner content
recursively, and re-adding the parentheses.
@AlisonNeedsCopilot
AlisonNeedsCopilot force-pushed the Users/AlisonNeedsCopilot/add-intermediary-measures-calculated-measures branch from 30fa542 to b64cf11 Compare February 10, 2026 04:55
@AlisonNeedsCopilot
AlisonNeedsCopilot changed the base branch from Users/AlisonNeedsCopilot/quote-escape-bracket-multiple-ad-hoc-measures-calculated-measures to main February 10, 2026 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant