# Understanding Query Logic in BI Genius

BI Genius is not a black box. While it leverages powerful AI to understand and respond to user questions, every step of the process is **explainable, auditable, and grounded in your data**.

This article explains how BI Genius handles user queries, what happens behind the scenes, and how we prioritize transparency in every interaction.

## What is Query Logic?

In BI Genius, ***query logic*** refers to the step-by-step process the system follows when a user asks a question—transforming natural language into an accurate, data-driven response.

This process involves:

1. **Understanding the user’s intent**
2. **Mapping the request to your data model**
3. **Constructing a DAX, SQL query or structured explanation**
4. **Returning the result with contextual reasoning**

Every one of these steps is traceable and explainable—by design.

## The Basic Query Flow

Here’s a simplified breakdown of how BI Genius processes a query:

#### 1. **Intent Parsing (AI Layer)**

* The user types a natural language question (e.g., “How did sales perform last quarter?”).
* Azure OpenAI interprets the request, identifies relevant metrics, dimensions, and time filters.

#### 2. **Context Assembly**

* BI Genius references your Power BI Semantic Model to locate the appropriate tables, measures, and filters.
* Optional external knowledge (e.g., glossary terms, documentation) may be used to disambiguate or enrich the query.

#### 3. **Query Generation**

* BI Genius builds a **DAX query** (or narrative logic) tailored to your model.
* This query is assembled transparently—you can view and audit the logic used.

#### 4. **Execution and Response**

* The query is executed against your dataset via XMLA or REST APIs.
* The response is returned to the user—optionally with a **plain-language explanation of how the result was calculated**.

***

### 🔍 Example

**User Prompt:**

> “What were the top 5 regions by profit last year?”

**BI Genius Explanation (visible to user):**

> “I calculated this by filtering your ‘Profit’ measure by last calendar year, then sorting by region and returning the top 5 results.”

**Technical View:**

```dax
DAX Expression

TOPN(5, 
     SUMMARIZE('Sales', 'Region'[Name], "Profit", [Total Profit]), 
     [Total Profit], DESC)
```

## Why Explainability Matters

Transparency builds trust, especially when AI is involved in data interpretation. BI Genius was built with explainability in mind to ensure:

**Accuracy** — users can verify the logic used in a response

**Trust** — especially in regulated industries or critical decision workflows

**Learning** — users grow more confident in both BI Genius and the underlying data

**Compliance** — audits are supported with traceable, interpretable query steps

## Customization & Control

* You can configure whether users see **just the answer**, or the underlying **query logic breakdown**.
* **Query Audit Logs** for Admins: View historical query chains and logic trees for traceability and providing troubleshooting assistance.&#x20;
