Show raised billing grouped by EntityName.

Instruction:
1) Guidelines
- Objective: Summarize raised billing amounts grouped by EntityName for the default window (last 2 years, financial year basis).
- Primary table: db_owner.NLP_IR_RaisedExcelTracker_tbl
- Measures: Raised billing → ClientTotalINR, aggregation SUM, monetary yes, currency column null
- Dimensions: EntityName
- Temporal filter: Default 2 years (financial year basis). Use Year/Month: (Year > 2023) OR (Year = 2023 AND Month >= 11)
- Row filtering: None
- Sorting and limit: None
- Joins: None
- Columns to SELECT: EntityName, SUM(ClientTotalINR)
- Notes/assumptions: Interpreted “raised billing” as ClientTotalINR; default window applies since no time period specified.

2) Instruction JSON
{
  "primary_table": "db_owner.NLP_IR_RaisedExcelTracker_tbl",
  "measures": [
    { "label": "Raised Billing (INR)", "column": "ClientTotalINR", "agg": "SUM", "monetary": true, "currency_column": null }
  ],
  "dimensions": ["EntityName"],
  "filters": ["(Year > 2023) OR (Year = 2023 AND Month >= 11)"],
  "time_window": { "basis": "financial", "start": "2023-11-01", "end": "2025-11-20", "use_to_date_for_os": false },
  "order_by": [],
  "top_n": null,
  "joins": [],
  "include_srno": false,
  "notes": "Assumed raised billing equals ClientTotalINR and applied default 2-year window."
}

SELECT
  EntityName,
  SUM(ClientTotalINR) AS [Raised Billing (INR)]
FROM db_owner.NLP_IR_RaisedExcelTracker_tbl
GROUP BY EntityName;


Instruction:
1) Guidelines
- 1) Objective: List realization records that have a TDS amount, for the default last 2 financial years.
- 2) Primary table: db_owner.NLP_IR_RealizationExcelTracker_tbl
- 3) Measures:
  - TDS Amount → TDSAmt, aggregation NONE, monetary yes, currency column null
  - Total Realised → TotalRealised, aggregation NONE, monetary yes, currency column null
- 4) Dimensions: ClientName, Matter, BillNumber, BillDate
- 5) Temporal filter: Default to last 2 financial years (Apr–Mar). Use Year/Month mapping:
  - SQL-ready: ((Year > 2023) OR (Year = 2023 AND Month >= 4)) AND ((Year < 2025) OR (Year = 2025 AND Month <= 11))
- 6) Row filtering: TDSAmt IS NOT NULL AND TDSAmt > 0
- 7) Sorting and limit: None
- 8) Joins: None
- 9) Columns to SELECT: ClientName, Matter, BillNumber, BillDate, TotalRealised, TDSAmt
- 10) Notes/assumptions: Assumed “with TDS amount” means records where TDSAmt > 0 and applied default last-2-years financial window.

2) Instruction JSON
{
  "primary_table": "db_owner.NLP_IR_RealizationExcelTracker_tbl",
  "measures": [
    { "label": "TDS Amount", "column": "TDSAmt", "agg": "NONE", "monetary": true, "currency_column": null },
    { "label": "Total Realised", "column": "TotalRealised", "agg": "NONE", "monetary": true, "currency_column": null }
  ],
  "dimensions": ["ClientName", "Matter", "BillNumber", "BillDate"],
  "filters": [
    "TDSAmt IS NOT NULL",
    "TDSAmt > 0",
    "((Year > 2023) OR (Year = 2023 AND Month >= 4)) AND ((Year < 2025) OR (Year = 2025 AND Month <= 11))"
  ],
  "time_window": { "basis": "financial", "start": "2023-04-01", "end": "2025-11-30", "use_to_date_for_os": false },
  "order_by": [],
  "top_n": null,
  "joins": [],
  "include_srno": false,
  "notes": "Defaulted to last two financial years; included only records with TDSAmt > 0."
}

SELECT
  ClientName,
  Matter,
  BillNumber,
  BillDate,
  TotalRealised,
  TDSAmt
FROM db_owner.NLP_IR_RealizationExcelTracker_tbl
WHERE TDSAmt IS NOT NULL
  AND TDSAmt > 0;


Instruction:
1) Guidelines
- Objective: Return top 5 TLs with highest WIP amount.
- Primary table: db_owner.NLP_IR_WIPExcelTracker_tbl
- Measures: Total WIP → WIPAMT, aggregation SUM, monetary yes, currency column null
- Dimensions: TL
- Temporal filter: Financial Year basis, last two financial years assumed Apr 2023 to Mar 2025; use Month/Year. Predicate: (Year > 2023 OR (Year = 2023 AND Month >= 4)) AND (Year < 2025 OR (Year = 2025 AND Month <= 3))
- Row filtering: None
- Sorting and limit: Order by SUM(WIPAMT) DESC; limit to top 5
- Joins: None
- Columns to SELECT: TL, SUM(WIPAMT)
- Notes/assumptions: Interpreted “most WIP” as WIP amount (₹), not hours. Used two completed financial years (Apr 2023–Mar 2025) for the default window.

2) Instruction JSON
{
  "primary_table": "db_owner.NLP_IR_WIPExcelTracker_tbl",
  "measures": [
    { "label": "Total WIP Amount", "column": "WIPAMT", "agg": "SUM", "monetary": true, "currency_column": null }
  ],
  "dimensions": ["TL"],
  "filters": [
    "(Year > 2023 OR (Year = 2023 AND Month >= 4)) AND (Year < 2025 OR (Year = 2025 AND Month <= 3))"
  ],
  "time_window": { "basis": "financial", "start": "2023-04-01", "end": "2025-03-31", "use_to_date_for_os": false },
  "order_by": [{ "expr": "SUM(WIPAMT)", "dir": "DESC" }],
  "top_n": 5,
  "joins": [],
  "include_srno": false,
  "notes": "Assumed WIP = amount; used two completed financial years for default window."
}

SELECT TOP 5
  TL,
  SUM(WIPAMT) AS TotalWIPAmount
FROM db_owner.NLP_IR_WIPExcelTracker_tbl
GROUP BY TL
ORDER BY SUM(WIPAMT) DESC;


Instruction:
1) Guidelines
- Objective: Return outstanding rows where Client IP OS is greater than Own IP OS.
- Primary table: db_owner.NLP_IR_OSExcelTracker_tbl
- Measures: OS Amount → [OS INR], aggregation NONE, monetary yes, currency column [Billing Currency]
- Dimensions: [Client Name], [Bill No], [Bill Dt]
- Temporal filter: No explicit time given; apply default last 2 years using Month_StartDate/Month_EndDate. Use filter: Month_StartDate >= '2023-11-01' AND Month_EndDate <= '2025-11-20'
- Row filtering: [Client IP OS] > [Own IP OS]
- Sorting and limit: None
- Joins: None
- Columns to SELECT: [Client Name], [Bill No], [Bill Dt], [Billing Currency], [OS INR], [Client IP OS], [Own IP OS]
- Notes/assumptions: Default window applied as last 2 years up to today; not using [To Date] since the question isn’t an “as of” cut-off request.

2) Instruction JSON
{
  "primary_table": "db_owner.NLP_IR_OSExcelTracker_tbl",
  "measures": [
    { "label": "OS Amount", "column": "[OS INR]", "agg": "NONE", "monetary": true, "currency_column": "[Billing Currency]" }
  ],
  "dimensions": ["[Client Name]", "[Bill No]", "[Bill Dt]"],
  "filters": ["[Client IP OS] > [Own IP OS]", "Month_StartDate >= '2023-11-01'", "Month_EndDate <= '2025-11-20'"],
  "time_window": { "basis": "financial", "start": "2023-11-01", "end": "2025-11-20", "use_to_date_for_os": false },
  "order_by": [],
  "top_n": null,
  "joins": [],
  "include_srno": false,
  "notes": "Default last 2 years applied via Month_StartDate/Month_EndDate; not an 'as of' query so [To Date] not used."
}

SELECT
  [Client Name],
  [Bill No],
  [Bill Dt],
  [Billing Currency],
  [OS INR],
  [Client IP OS],
  [Own IP OS]
FROM db_owner.NLP_IR_OSExcelTracker_tbl
WHERE [Client IP OS] > [Own IP OS]
  AND Month_StartDate >= '2023-11-01'
  AND Month_EndDate <= '2025-11-20';

SELECT
  [Client Name],
  [Bill No],
  [Bill Dt],
  [Billing Currency],
  [OS INR],
  [Client IP OS],
  [Own IP OS]
FROM db_owner.NLP_IR_OSExcelTracker_tbl
WHERE [Client IP OS] > [Own IP OS];


Show realisation running total for a client.

Instruction:
1) Guidelines
- Objective: Return month-wise realisation and a cumulative (running) total for a specified client over the default financial window.
- Primary table: db_owner.NLP_IR_RealizationExcelTracker_tbl
- Measures:
  - Realised INR → TotalRealised, aggregation SUM, monetary yes, currency column null (amounts are in INR)
  - Running Total INR → cumulative SUM of TotalRealised ordered by Year, Month, monetary yes, currency column null
- Dimensions: Year, Month
- Temporal filter: Default financial window (last 2 financial years). SQL-ready predicate:
  - (Year > 2023 OR (Year = 2023 AND Month >= 4)) AND ((Year < 2025) OR (Year = 2025 AND Month <= 11))
- Row filtering: ClientName = '<client_name_param>'
- Sorting and limit: Order by Year ASC, Month ASC; no TOP or ranking limit
- Joins: None
- Columns to SELECT: Year, Month, SUM(TotalRealised) as RealisedINR, RunningTotalINR (cumulative)
- Notes/assumptions: Amounts are already in INR; requires a specific client name parameter.

2) Instruction JSON
{
  "primary_table": "db_owner.NLP_IR_RealizationExcelTracker_tbl",
  "measures": [
    { "label": "Realised INR", "column": "TotalRealised", "agg": "SUM", "monetary": true, "currency_column": "null" },
    { "label": "Running Total INR", "column": "TotalRealised", "agg": "SUM", "monetary": true, "currency_column": "null" }
  ],
  "dimensions": ["Year", "Month"],
  "filters": [
    "(Year > 2023 OR (Year = 2023 AND Month >= 4))",
    "((Year < 2025) OR (Year = 2025 AND Month <= 11))",
    "ClientName = '<client_name_param>'"
  ],
  "time_window": { "basis": "financial", "start": "2023-04-01", "end": "2025-11-20", "use_to_date_for_os": false },
  "order_by": [{ "expr": "Year", "dir": "ASC" }, { "expr": "Month", "dir": "ASC" }],
  "top_n": null,
  "joins": [],
  "include_srno": false,
  "notes": "Compute running total using a window SUM over Year, Month; amounts are in INR. Provide client name."}

SELECT
  Year,
  Month,
  SUM(TotalRealised) AS RealisedINR,
  SUM(SUM(TotalRealised)) OVER (ORDER BY Year, Month ROWS UNBOUNDED PRECEDING) AS RunningTotalINR
FROM db_owner.NLP_IR_RealizationExcelTracker_tbl
WHERE ClientName = '<client_name_param>'
GROUP BY Year, Month
ORDER BY Year ASC, Month ASC;

SELECT
  Year,
  Month,
  RealisedINR,
  SUM(RealisedINR) OVER (ORDER BY Year, Month ROWS UNBOUNDED PRECEDING) AS RunningTotalINR
FROM (
  SELECT
    Year,
    Month,
    SUM(TotalRealised) AS RealisedINR
  FROM db_owner.NLP_IR_RealizationExcelTracker_tbl
  WHERE ClientName = '<client_name_param>'
  GROUP BY Year, Month
) m
ORDER BY Year ASC, Month ASC;


Find clients with both WIP & raised invoices.

Instruction:
1) Guidelines
- 1) Objective: Return the list of clients that have entries in both WIP and Raised (billing) within the default last 2 years window.
- 2) Primary table: db_owner.NLP_IR_WIPExcelTracker_tbl
- 3) Measures: None (no aggregations; purely presence-based).
- 4) Dimensions: Client
- 5) Temporal filter: Financial year basis; use Month/Year columns. Window: from Apr 2023 to Nov 2025 (inclusive). SQL-ready filters:
  - For WIP: (t1.Year > 2023 OR (t1.Year = 2023 AND t1.Month >= 4)) AND (t1.Year < 2025 OR (t1.Year = 2025 AND t1.Month <= 11))
  - For Raised: (t2.Year > 2023 OR (t2.Year = 2023 AND t2.Month >= 4)) AND (t2.Year < 2025 OR (t2.Year = 2025 AND t2.Month <= 11))
- 6) Row filtering: None.
- 7) Sorting and limit: None.
- 8) Joins: Inner join to db_owner.NLP_IR_RaisedExcelTracker_tbl on t1.Client = t2.ClientName.
- 9) Columns to SELECT: DISTINCT Client.
- 10) Notes/assumptions: Client matching is done by name only (t1.Client vs t2.ClientName); this may include multiple matters per client, which is acceptable for the objective.

2) Instruction JSON
{
  "primary_table": "db_owner.NLP_IR_WIPExcelTracker_tbl",
  "measures": [],
  "dimensions": ["Client"],
  "filters": [
    "(t1.Year > 2023 OR (t1.Year = 2023 AND t1.Month >= 4)) AND (t1.Year < 2025 OR (t1.Year = 2025 AND t1.Month <= 11))",
    "(t2.Year > 2023 OR (t2.Year = 2023 AND t2.Month >= 4)) AND (t2.Year < 2025 OR (t2.Year = 2025 AND t2.Month <= 11))"
  ],
  "time_window": { "basis": "financial", "start": "2023-04-01", "end": "2025-11-20", "use_to_date_for_os": false },
  "order_by": [],
  "top_n": null,
  "joins": [
    { "table": "db_owner.NLP_IR_RaisedExcelTracker_tbl", "on": ["t1.Client = t2.ClientName"] }
  ],
  "include_srno": false,
  "notes": "Client list derived by name match across WIP and Raised within last two financial years up to current month."
}

SELECT DISTINCT t1.Client
FROM db_owner.NLP_IR_WIPExcelTracker_tbl AS t1
INNER JOIN db_owner.NLP_IR_RaisedExcelTracker_tbl AS t2
  ON t1.Client = t2.ClientName
WHERE (t1.Year > 2023 OR (t1.Year = 2023 AND t1.Month >= 4))
  AND (t1.Year < 2025 OR (t1.Year = 2025 AND t1.Month <= 11))
  AND (t2.Year > 2023 OR (t2.Year = 2023 AND t2.Month >= 4))
  AND (t2.Year < 2025 OR (t2.Year = 2025 AND t2.Month <= 11));

SELECT DISTINCT w.Client
FROM db_owner.NLP_IR_WIPExcelTracker_tbl AS w
INNER JOIN db_owner.NLP_IR_RaisedExcelTracker_tbl AS r
  ON w.Client = r.ClientName;


Show consolidated summary per TL (WIP + Billing + Realisation).

Instruction:
1) Guidelines
- Objective: One consolidated row per TL showing totals for WIP, Billing, and Realisation in INR over the default last 2 financial years.
- Primary table: None (requires combining three tables)
- Measures:
  - WIP Amount → db_owner.NLP_IR_WIPExcelTracker_tbl.WIPAMT, SUM, monetary: yes, currency_column: null
  - Billing Amount → db_owner.NLP_IR_RaisedExcelTracker_tbl.ClientTotalINR, SUM, monetary: yes, currency_column: null
  - Realised Amount → db_owner.NLP_IR_RealizationExcelTracker_tbl.TotalRealised, SUM, monetary: yes, currency_column: null
- Dimensions: TL
- Temporal filter: Financial-year basis. Use Month_StartDate and Month_EndDate where available.
  - Filter: (Month_StartDate >= '2023-04-01' AND Month_EndDate <= '2025-11-20') on each of the three tables
- Row filtering: None
- Sorting and limit: None
- Joins: Required to consolidate per TL. Join keys: TL across the three aggregated sets. Use FULL OUTER JOINs on TL to retain TLs present in only one or two sources.
- Columns to SELECT: TL, SUM(WIPAMT) as WIPAmount, SUM(ClientTotalINR) as BillingAmount, SUM(TotalRealised) as RealisedAmount
- Notes/assumptions: Billing interpreted as ClientTotalINR from the Raised table; all measures are INR.

2) Instruction JSON
{
  "primary_table": null,
  "measures": [
    { "label": "WIPAmount", "column": "db_owner.NLP_IR_WIPExcelTracker_tbl.WIPAMT", "agg": "SUM", "monetary": true, "currency_column": null },
    { "label": "BillingAmount", "column": "db_owner.NLP_IR_RaisedExcelTracker_tbl.ClientTotalINR", "agg": "SUM", "monetary": true, "currency_column": null },
    { "label": "RealisedAmount", "column": "db_owner.NLP_IR_RealizationExcelTracker_tbl.TotalRealised", "agg": "SUM", "monetary": true, "currency_column": null }
  ],
  "dimensions": ["TL"],
  "filters": [
    "db_owner.NLP_IR_WIPExcelTracker_tbl.Month_StartDate >= '2023-04-01' AND db_owner.NLP_IR_WIPExcelTracker_tbl.Month_EndDate <= '2025-11-20'",
    "db_owner.NLP_IR_RaisedExcelTracker_tbl.Month_StartDate >= '2023-04-01' AND db_owner.NLP_IR_RaisedExcelTracker_tbl.Month_EndDate <= '2025-11-20'",
    "db_owner.NLP_IR_RealizationExcelTracker_tbl.Month_StartDate >= '2023-04-01' AND db_owner.NLP_IR_RealizationExcelTracker_tbl.Month_EndDate <= '2025-11-20'"
  ],
  "time_window": { "basis": "financial", "start": "2023-04-01", "end": "2025-11-20", "use_to_date_for_os": false },
  "order_by": [],
  "top_n": null,
  "joins": [
    { "table": "db_owner.NLP_IR_RaisedExcelTracker_tbl", "on": ["w.TL = r.TL"] },
    { "table": "db_owner.NLP_IR_RealizationExcelTracker_tbl", "on": ["COALESCE(w.TL, r.TL) = z.TL"] }
  ],
  "include_srno": false,
  "notes": "Use FULL OUTER JOINs on TL between aggregated WIP (w), Raised (r), and Realization (z) to retain all TLs; Billing uses ClientTotalINR."
}

SELECT
  COALESCE(w.TL, r.TL, z.TL) AS TL,
  ISNULL(w.WIPAmount, 0) AS WIPAmount,
  ISNULL(r.BillingAmount, 0) AS BillingAmount,
  ISNULL(z.RealisedAmount, 0) AS RealisedAmount
FROM
(
  SELECT
    TL,
    SUM(WIPAMT) AS WIPAmount
  FROM db_owner.NLP_IR_WIPExcelTracker_tbl
  WHERE Month_StartDate >= '2023-04-01' AND Month_EndDate <= '2025-11-20'
  GROUP BY TL
) w
FULL OUTER JOIN
(
  SELECT
    TL,
    SUM(ClientTotalINR) AS BillingAmount
  FROM db_owner.NLP_IR_RaisedExcelTracker_tbl
  WHERE Month_StartDate >= '2023-04-01' AND Month_EndDate <= '2025-11-20'
  GROUP BY TL
) r
  ON w.TL = r.TL
FULL OUTER JOIN
(
  SELECT
    TL,
    SUM(TotalRealised) AS RealisedAmount
  FROM db_owner.NLP_IR_RealizationExcelTracker_tbl
  WHERE Month_StartDate >= '2023-04-01' AND Month_EndDate <= '2025-11-20'
  GROUP BY TL
) z
  ON COALESCE(w.TL, r.TL) = z.TL

SELECT
  COALESCE(w.TL, r.TL, z.TL) AS TL,
  ISNULL(w.WIPAmount, 0) AS WIPAmount,
  ISNULL(r.BillingAmount, 0) AS BillingAmount,
  ISNULL(z.RealisedAmount, 0) AS RealisedAmount
FROM (
  SELECT TL, SUM(WIPAMT) AS WIPAmount
  FROM db_owner.NLP_IR_WIPExcelTracker_tbl
  GROUP BY TL
) w
FULL OUTER JOIN (
  SELECT TL, SUM(ClientTotalINR) AS BillingAmount
  FROM db_owner.NLP_IR_RaisedExcelTracker_tbl
  GROUP BY TL
) r
  ON w.TL = r.TL
FULL OUTER JOIN (
  SELECT TL, SUM(TotalRealised) AS RealisedAmount
  FROM db_owner.NLP_IR_RealizationExcelTracker_tbl
  GROUP BY TL
) z
  ON COALESCE(w.TL, r.TL) = z.TL


Show distinct matters across all tables.

Instruction:
1) Guidelines
- Objective: Return a unique list of matter names drawn from all six NLP tracker tables.
- Primary table: db_owner.NLP_IR_RaisedExcelTracker_tbl
- Measures: None
- Dimensions: None
- Temporal filter: None (no date window needed for distinct matter names)
- Row filtering: None
- Sorting and limit: None
- Joins: None — use UNION across tables
- Columns to SELECT: A single column aliased as Matter from each table:
  - db_owner.NLP_IR_RaisedExcelTracker_tbl.Matter AS Matter
  - db_owner.NLP_IR_RealizationExcelTracker_tbl.Matter AS Matter
  - db_owner.NLP_IR_CreditNoteExcelTracker_tbl.Matter AS Matter
  - db_owner.NLP_IR_WIPExcelTracker_tbl.Matter AS Matter
  - db_owner.NLP_IR_LocationwiseWIPExcelTracker_tbl.Matter AS Matter
  - db_owner.NLP_IR_OSExcelTracker_tbl.[Matter Name] AS Matter
- Notes/assumptions: Apply DISTINCT over the UNION of these selects; no additional filters.

2) Instruction JSON
{
  "primary_table": "db_owner.NLP_IR_RaisedExcelTracker_tbl",
  "measures": [],
  "dimensions": [],
  "filters": [],
  "time_window": { "basis": "financial", "start": null, "end": null, "use_to_date_for_os": false },
  "order_by": [],
  "top_n": null,
  "joins": [],
  "include_srno": false,
  "notes": "Select Matter (aliased as Matter) from each table and UNION ALL them, then apply DISTINCT. Tables/columns: Raised.Matter, Realization.Matter, CreditNote.Matter, WIP.Matter, LocationwiseWIP.Matter, OS.[Matter Name] aliased to Matter."
}

SELECT DISTINCT Matter
FROM (
    SELECT Matter FROM db_owner.NLP_IR_RaisedExcelTracker_tbl
    UNION ALL
    SELECT Matter FROM db_owner.NLP_IR_RealizationExcelTracker_tbl
    UNION ALL
    SELECT Matter FROM db_owner.NLP_IR_CreditNoteExcelTracker_tbl
    UNION ALL
    SELECT Matter FROM db_owner.NLP_IR_WIPExcelTracker_tbl
    UNION ALL
    SELECT Matter FROM db_owner.NLP_IR_LocationwiseWIPExcelTracker_tbl
    UNION ALL
    SELECT [Matter Name] AS Matter FROM db_owner.NLP_IR_OSExcelTracker_tbl
) AS u;