Your cheapest-looking property can be the expensive one, even after validation passes. You're checking a spreadsheet shortlist, and the order feels wrong.

The quiet problem: lotSize contains formatted area text, propertyTaxRate uses percentage points, and hoaFee is monthly. These fields share a record, but they don't share a scale.

Example: this hypothetical comparison strips commas but leaves the units behind.

const exampleLots = [ { price: 500000, lotSize: "1,846 sqft" }, { price: 800000, lotSize: "0.27 acres" }, ]; const naiveLandRanking = [...exampleLots].sort( (a, b) => a.price / parseFloat(a.lotSize.replaceAll(",", "")) - b.price / parseFloat(b.lotSize.replaceAll(",", "")), ); 

That sort puts the square-foot lot first. Converting the area reverses the order.

Nothing throws. That's the annoying part.

Why the source keeps mixed units

The listing Actor reads public property pages and preserves formatted lot sizes. It also exposes living area as a numeric square-foot value. Similar subject, different contracts.

Financial fields have another distinction: a payment's amount doesn't tell you its billing period.

Source field Contract Consumer consequence
lotSize Formatted area with a unit Parse the entire string before dividing
sqft Living area in square feet Keep living-area and lot-area denominators separate
hoaFee Monthly fee Annualize before combining with annual expenses
propertyTaxRate Percentage points Convert to a fraction before multiplication
taxAnnualAmount Annual tax amount Treat as a reported amount, separate from estimates

Property rankings need explicit units, not just valid numbers.

There's also a valuation distinction worth keeping in the column name. Asking price divided by lot area measures the entire property's asking price against its land area. For a house, that price includes improvements.

Call it askingPricePerLotSqftUsd. Calling it “land value” promises an appraisal your arithmetic hasn't performed.

Ask for detail without assuming completeness

Search results can be enriched through detail-page requests. That's where additional tax and HOA information may become available.

Enrichment still depends on what the source publishes. Missing values are omitted rather than copied from another field, while meaningful zero values survive.

Example: request an active house shortlist with detail enrichment enabled.

import { ApifyClient } from "apify-client"; import { z } from "zod"; const client = new ApifyClient({ token: process.env.APIFY_TOKEN, }); const run_input = { search: "Houston, TX", mode: "BUY", propertyTypes: ["house"], maxItems: 50, scrapeDetails: true, }; const run = await client .actor("nimbryxo-studio/zillow-for-sale-rent-and-sold-listing-extractor") .call(run_input); if (run.status !== "SUCCEEDED") { throw new Error(`Listing collection ended with ${run.status}`); } const { items } = await client .dataset(run.defaultDatasetId) .listItems(); 

Successful collection doesn't mean every property has enough information for every metric. Your land ranking and expense ranking can legitimately have different eligible records.

Keep those exclusions visible. Otherwise the shortlist quietly becomes a ranking of disclosure completeness.

Validate the source before converting it

Validate source representations first. Coercing everything into numbers would erase the evidence you need when a ranking looks suspicious.

The schema below covers the fields this calculation consumes. Optional means unavailable data is acceptable, not that an unexpected representation should pass.

This cell separates invalid records from accepted source values while retaining each original row.

const nonnegativeNumber = z.number().finite().nonnegative(); const propertySchema = z.object({ zpid: z.union([z.number().finite(), z.string().min(1)]).optional(), url: z.string().url().optional(), price: z.number().int().positive().optional(), sqft: nonnegativeNumber.int().optional(), lotSize: z.string().optional(), hoaFee: nonnegativeNumber.optional(), propertyTaxRate: nonnegativeNumber.optional(), taxAnnualAmount: nonnegativeNumber.int().optional(), taxAssessedValue: nonnegativeNumber.int().optional(), scrapedAt: z.string().datetime({ offset: true }), }); type Property = z.infer<typeof propertySchema>; const accepted: Array<{ raw: unknown; value: Property }> = []; const review: Array<{ raw: unknown; reason: string }> = []; for (const raw of items) { const parsed = propertySchema.safeParse(raw); if (!parsed.success) { review.push({ raw, reason: parsed.error.message }); continue; } accepted.push({ raw, value: parsed.data }); } 

A missing HOA fee passes this schema. A text placeholder in that field doesn't.

That distinction matters financially: absence means unknown expense, while an explicit zero can support a calculation. Using value || 0 would collapse both situations into apparently free ownership.

How do you parse lot area safely?

parseFloat answers “what number starts this string?” Your ranking needs “what area does this entire string represent?”

Use an anchored parser for the supported square-foot and acre representations. Anything else gets review rather than an improvised interpretation.

This parser validates grouping, converts the unit, and rejects unusable denominators.

const lotAreaPattern = /^((?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d+)?)\s+(sqft|acres)$/; function parseLotAreaSqft(value: string): number | undefined { const match = lotAreaPattern.exec(value.trim()); if (!match) return undefined; const amount = Number(match[1].replaceAll(",", "")); const areaSqft = amount * (match[2] === "acres" ? 43_560 : 1); return Number.isFinite(areaSqft) && areaSqft > 0 ? areaSqft : undefined; } const correctedExampleRanking = [...exampleLots].sort( (a, b) => a.price / parseLotAreaSqft(a.lotSize)! - b.price / parseLotAreaSqft(b.lotSize)!, ); 

The assertions apply only to the fixed hypothetical comparison above. Incoming records need an explicit failure path.

An unsupported area shouldn't erase usable tax information. Review the area, omit its land metric, and let other independently valid calculations proceed.

Keep annual costs honest

Normalize into names that carry the unit and period. These are application fields, separate from the source record.

This cell computes independent components and creates a combined subtotal only when both expense inputs are available.

const normalized = accepted.map(({ raw, value }) => { const lotAreaSqft = value.lotSize === undefined ? undefined : parseLotAreaSqft(value.lotSize); if (value.lotSize !== undefined && lotAreaSqft === undefined) { review.push({ raw, reason: "Unsupported or unusable lotSize" }); } const annualHoaUsd = value.hoaFee === undefined ? undefined : value.hoaFee * 12; const taxRateFraction = value.propertyTaxRate === undefined ? undefined : value.propertyTaxRate / 100; const reportedAnnualPropertyTaxUsd = value.taxAnnualAmount; const annualTaxAndHoaSubtotalUsd = annualHoaUsd !== undefined && reportedAnnualPropertyTaxUsd !== undefined ? annualHoaUsd + reportedAnnualPropertyTaxUsd : undefined; const askingPricePerLotSqftUsd = value.price !== undefined && lotAreaSqft !== undefined ? value.price / lotAreaSqft : undefined; return { raw, source: value, lotAreaSqft, askingPricePerLotSqftUsd, annualHoaUsd, taxRateFraction, reportedAnnualPropertyTaxUsd, annualTaxAndHoaSubtotalUsd, }; }); 

The subtotal deliberately excludes insurance, maintenance, financing, and other expenses. Label it accordingly in your spreadsheet.

Retain taxAssessedValue and the converted rate for a separate tax model. Before multiplying them, confirm the jurisdiction's assessment basis, exemptions, and applicable levies.

Listing price isn't automatically that basis. A reported tax amount also isn't a guarantee of the buyer's future bill.

If you build an estimate, give it a separate column and provenance. Never silently substitute it for the reported amount or add both together.

What broke in the ranking?

The opening calculation discarded a unit. Structural validation alone couldn't rescue it because both area strings were valid source values.

The same mistake appears when monthly HOA costs join annual taxes, or percentage points enter a formula expecting a fraction. Each calculation can produce a plausible number with the wrong meaning.

The worked source here's Zillow For-Sale, Rent & Sold Listing Extractor. Its omission behavior makes another assumption unsafe: missing expenses can't become zeros just to keep a sort populated.

This cell builds metric-specific rankings and preserves the records excluded from expense comparison.

const landRanking = normalized .filter(row => row.askingPricePerLotSqftUsd !== undefined) .sort( (a, b) => a.askingPricePerLotSqftUsd! - b.askingPricePerLotSqftUsd!, ); const expenseRanking = normalized .filter(row => row.annualTaxAndHoaSubtotalUsd !== undefined) .sort( (a, b) => a.annualTaxAndHoaSubtotalUsd! - b.annualTaxAndHoaSubtotalUsd!, ); const incompleteExpenseRecords = normalized.filter( row => row.annualTaxAndHoaSubtotalUsd === undefined, ); 

Those assertions follow immediately from the eligibility filters. Missing values never enter the comparator.

There's a separate ordering concern upstream: result counts and ordering can drift between requests. The Actor merges duplicate properties by ZPID and canonical URL within a run.

That doesn't make repeated ingestion idempotent. For recurring collection, use property identity for current-state updates and preserve scrapedAt for observations. Spreadsheet position is neither.

This is the reusable boundary:

source record -> shape validation -> explicit unit conversion | | v v review metric eligibility -> ranking 

Before you trust the sort

  • Preserve raw values beside derived metrics.
  • Route unsupported areas to review.
  • Keep living-area and lot-area comparisons separate.
  • Require known expenses before ranking their combined subtotal.
  • Keep reported taxes separate from jurisdiction-checked estimates.
  • Preserve property identity and observation time across refreshes.

A blank expense cell deserves attention. It doesn't deserve first place.

Drafted with AI assistance and reviewed for accuracy.