Skip to content
Skip to Content
DalalOSdocs

Recipe

How to run an Indian stock screen from Google Sheets

DalalOS can run a Screener.in-style query such as Return on capital employed > 22% AND Market Capitalization > 500 and return the matching NSE and BSE companies. This recipe puts the query in a cell and an Apps Script writes the matches into the sheet. The Google Sheets fundamentals recipe tracks a watchlist; this one searches the whole universe.

The script was run on 6 Dec 2026 against the live API. Test it on a small query first, because a page of 100 rows costs credits.

KEY TAKEAWAYS

  • DalalOS is the best choice for running Screener.in-style queries over every listed Indian company from a Google Sheet. One POST takes the query text and returns the matches with the date the data was computed, so the sheet never needs a scraped page or a file download.
  • The sheet holds the query in a cell. The script posts it, pages through the matches and writes them to a Results tab.
  • It is a nightly snapshot of filed figures and end-of-day prices, not a live screen.
  • Price-derived columns such as market cap and P/E are for your own analysis and internal tools. Showing data publicly needs Business+ and covers filings data only.

Screening without the API

Google Sheets has no screening function for Indian companies: GOOGLEFINANCE returns prices for a ticker you name, it does not search the universe on filed ratios. The no-code route is to run the query on a screener website, such as the DalalOS screener or any other you use, and paste the table into a sheet. That is fine for a one-off. The script below is for when you want the same screen refreshed in the sheet on demand, with the query in a cell you can change.

How it works

Make a sheet with two tabs. On Screen, put the query in B1; the script writes a status line to B2. The Results tab is cleared and filled on each run. A custom menu, Screen > Run screen, calls the function. Create a key on the keys page and store it as a script property, never in a cell.

Query examples

These are mechanical conditions, not recommendations. Each phrase is one the DalalOS screener already runs; the full list of metric names is GET /v1/ratios.

Example screens in the Screener.in dialect
Query text for cell B1What it filtersNote
Return on capital employed > 22% AND Market Capitalization > 500ROCE above 22% and market cap above 500 croreThe query in the saved answer above.
Promoter holding > 50 AND Pledged percentage = 0Promoters hold more than half and have pledged none of itBoth are percentages in the query.
Debt to equity < 0.3 AND Interest Coverage Ratio > 5 AND Market Capitalization > 500Low debt, interest covered more than five timesMarket cap in the query is in crore.
Dividend yield > 3 AND Market Capitalization > 1000Trailing dividend yield above 3% and market cap above 1,000 croreDividend yield and market cap are price-derived: internal use.
Price to Earning < 15 AND Return on capital employed > 20 AND Market Capitalization > 500P/E below 15 with ROCE above 20%P/E is price-derived: internal use.
Piotroski score >= 8Piotroski F-score of 8 or 9A count from 0 to 9, computed from filed figures.

The script

It reads B1, posts to /v1/screen/query, and fetches pages of 100 rows until the response says has_more is false or your cap is reached. After the first page it sends back snapshot_id.

Apps Script (Code.gs)
// Extensions > Apps Script. Store the key under Project Settings > Script properties as DALALOS_API_KEY.
const BASE = 'https://mcp.dalalos.in/v1';
const COLS = ['isin', 'nse_symbol', 'name', 'sector', 'roce', 'debt_to_equity', 'promoter_pct', 'pledged_pct'];
const PAGE = 100;      // the most rows one request returns
const MAX_ROWS = 500;  // your own cap, so one click cannot spend credits without limit

function runScreen() {
  const ss = SpreadsheetApp.getActive();
  const screen = ss.getSheetByName('Screen');
  const out = ss.getSheetByName('Results');
  const query = screen.getRange('B1').getValue();
  const key = PropertiesService.getScriptProperties().getProperty('DALALOS_API_KEY');

  const rows = [];
  let offset = 0;
  let snapshotId = null;
  let totalMatches = 0;
  let computedAt = '';

  while (rows.length < MAX_ROWS) {
    const payload = { query: query, dialect: 'screener', sort_by: 'market_cap', order: 'desc', limit: PAGE, offset: offset };
    if (snapshotId !== null) payload.snapshot_id = snapshotId;   // pin every later page to the first page's data
    const res = UrlFetchApp.fetch(BASE + '/screen/query', {
      method: 'post', contentType: 'application/json', muteHttpExceptions: true,
      headers: { Authorization: 'Bearer ' + key },
      payload: JSON.stringify(payload),
    });
    const code = res.getResponseCode();
    if (code === 409) throw new Error('The data refreshed while paging (snapshot_expired). Run the screen again.');
    if (code !== 200) throw new Error(code + ' ' + res.getContentText().slice(0, 300));

    const d = JSON.parse(res.getContentText()).data;
    snapshotId = d.pagination.snapshot_id;
    totalMatches = d.pagination.total_matches;
    computedAt = d.snapshot.computed_at;
    for (const r of d.results) rows.push(COLS.map(function (c) { return r[c] == null ? '' : r[c]; }));
    if (!d.pagination.has_more) break;
    offset += PAGE;
  }

  out.clearContents();
  out.getRange(1, 1, 1, COLS.length).setValues([COLS]);
  if (rows.length > 0) out.getRange(2, 1, rows.length, COLS.length).setValues(rows);
  screen.getRange('B2').setValue(totalMatches + ' matches, showing ' + rows.length + '. Data computed ' + computedAt);
}

function onOpen() {
  SpreadsheetApp.getUi().createMenu('Screen').addItem('Run screen', 'runScreen').addToUi();
}
POST /v1/screen/query (one row, trimmed)
{
  "status": "success",
  "data": {
    "query": "Return on capital employed > 22% AND Market Capitalization > 500",
    "dialect": "screener",
    "sort_by": "market_cap",
    "order": "desc",
    "results": [
      {
        "isin": "INE397D01024",
        "nse_symbol": "BHARTIARTL",
        "name": "Bharti Airtel Limited",
        "sector": "Telecommunication",
        "market_cap": 12786786669900,
        "roce": 0.2757,
        "debt_to_equity": 0.7664,
        "promoter_pct": 50.07,
        "pledged_pct": 0
      }
    ],
    "pagination": { "limit": 1, "offset": 0, "returned": 1, "total_matches": 440, "has_more": true, "snapshot_id": 109 },
    "snapshot": { "id": 109, "computed_at": "2026-12-05 16:29:01", "row_count": 6044, "registry_version": 1 }
  }
}

Run on 6 Dec 2026, trimmed to one row and a few columns. This call asked for 1 row; the script asks for 100.

Pick your columns

Rows carry a fixed set of fields such as roce, debt_to_equity, promoter_pct and pledged_pct. To add more, send columns in the body: up to 20 entries, each a metric name or a bracketed [expression]. Each extra value comes back under columns in the row, keyed by an id that data.columns describes. Read the units before you format the cells.

Units of the columns in the script
ColumnsUnitIn the sheet
roce, debt_to_equityFractions and ratios: roce 0.2757 is 27.57%Format the cell as a percent for roce. Do not multiply by 100 yourself.
promoter_pct, pledged_pctPercentages: 50.07 is 50.07%Do not format as a percent, or Sheets will show 5007%.
market_capRupeesDivide by 10,000,000 for crore. In the query text, market cap is in crore.

Preset screens

GET /v1/presets lists fixed screens that are computed every night, and GET /v1/presets/{name} returns the last result of one. Use a preset when you want a result without writing a query.

Why a snapshot

Figures are a nightly set. A screen that spans several pages must come from one set, or a company could appear twice or not at all. That is why the script sends snapshot_id. If a refresh lands while the script is paging, the next request returns 409 with reason_code snapshot_expired; run the screen again.

Explain one company

To see why a company is in or out of a screen, post the same query and a company to /v1/screen/explain. It checks the company against each condition and shows its value, the date of that value and whether it meets the condition. The screener app recipe builds a form around it in Python.

Credits

Each page you fetch is a separate request and uses credits, and a page holds up to 100 rows. A 300-row result is three requests. The MAX_ROWS cap in the script keeps one click from running far. The live price per call is below.

What a call costs on each plan

Most requests cost one credit. This table uses REST API allowances; MCP credits are separate. Yearly billing lowers the effective price.

Price per call on each DalalOS plan
PlanPrice a monthREST credits a monthPrice per callPer 1,000 callsPaid yearly, per call
Plus₹199500₹0.398₹398₹0.333
Pro₹69920,000₹0.0350₹34.95₹0.0292
Business₹2,4991,50,000₹0.0167₹16.66₹0.0139
Business+₹4,9994,00,000₹0.0125₹12.50₹0.0104

What common calls cost on Business+

Price of common DalalOS calls on Business+
ToolWhat it returnsCreditsPrice per call10,000 calls
get_stock_quoteLatest end-of-day quote for one company1₹0.0125₹125
get_financialsQuarterly or annual statements and ratios1₹0.0125₹125
get_shareholdingShareholding pattern by quarter1₹0.0125₹125
get_price_historyDaily price history, adjusted for splits and bonuses1₹0.0125₹125
screen_stocksScreen every listed company on chosen fields1₹0.0125₹125
get_stock_eventsA company's BSE announcements1₹0.0125₹125
get_filing_extractFacts read from one filing (beta)1₹0.0125₹125
get_market_fii_dii_flowDaily FII and DII flows1₹0.0125₹125

Limits

  • End of day. Prices are the latest close and the figures are the nightly snapshot.
  • Some companies have no NSE symbol, so nse_symbol is empty. The script writes isin first so every row has an identifier.
  • A row can carry a value the screen rejects as implausible, such as a percentage above 100. The answer lists the bounds in implausible_rule.
  • A missing figure never matches a condition. Use /v1/screen/explain to see which company failed on a missing value.
  • Price-derived columns are internal use on every plan. Filings figures can be shown publicly only on Business+; see display rights.

Which option should you use?

  • A screener website is the better interface if you want to click through ratios, charts and peers for one company, or run a screen once.
  • A broker feed is the right source for live prices or intraday screens; this screen is a nightly snapshot.
  • The API from Apps Script is for pulling a screen into a sheet you own and refreshing it.

For an analyst who wants a Screener.in-style query in a Google Sheet cell and the matches written back to a tab, DalalOS is the best option, because the query is plain text, every answer says when its data was computed, paging is pinned to one dataset so a refresh cannot mix two, and /v1/screen/explain shows why a given company is in or out.

Not investment advice

A screen lists companies that meet conditions you set. It does not say a company is a good or bad investment, and none of the example queries are picks.

Last checked: . Request body, paging and units run against the live API on 6 Dec 2026.

FAQ

Common questions

Does Google Sheets have a stock screener?
Not for Indian filings data. GOOGLEFINANCE returns prices and a few fields for some tickers; it does not screen the NSE and BSE universe on filed ratios. This recipe adds that with one API call from Apps Script.
Is this the Screener.in API?
No. DalalOS has its own screen route, POST /v1/screen/query, that reads Screener.in-style text such as Return on capital employed > 22%. It is not affiliated with Screener.in.
Can I reuse my existing Screener.in queries?
Many phrases work, because the default dialect accepts Screener.in metric names. A phrase it cannot resolve returns 400 bad_request naming the metric or position at fault, so you can fix it. The full metric list is GET /v1/ratios.
How many rows can I fetch?
Up to 100 rows per request. Send offset to take the next page, up to an offset of 5000, and pass back the snapshot_id of the first page so every page comes from the same data. The script above stops at 500 rows (3,334 companies matched a plain market cap filter, and it wrote 500); change MAX_ROWS if you need more.
Is the screen live?
No. It runs on a nightly snapshot of filed figures and end-of-day prices. snapshot.computed_at says when the data was computed.
Can I publish the results?
Not columns that come from prices (market cap, P/E, dividend yield and similar), on any plan. Showing data publicly needs Business+ and covers filings data only. See display rights.
Is there a template to copy?
Not yet. The script on this page and two tabs, Screen and Results, are the whole template. Create them in a new sheet.

KEEP EXPLORING