Back to all articles

Connect a people counting sensor to Power BI for occupancy data

Connect a people counting sensor Power BI workflow through SQL storage. Calculate occupancy, prevent duplicate counts and build a reliable reporting view.

KIEditorial TeamNov 24, 2026 — 11 min read
Connect a people counting sensor to Power BI for occupancy data

Instead of copying people counting sensor readings into spreadsheets, send decoded readings to a SQL table and import that table into Power BI for repeatable occupancy reporting. Calculate occupancy before visualising it, then set up refresh so the report follows your stored data rather than manual exports.

TL;DR
  • A people counting sensor Power BI workflow needs decoded readings, persistent storage and an explicit occupancy calculation.
  • Store entry and exit events before calculating occupancy; duplicate deliveries must not increase the count.
  • Power BI Import reports update through refresh, not whenever a sensor transmits.
  • Kilo Electronics supplies IoT hardware; the reporting pipeline remains a separate part of your installation.

Why this matters

Footfall and occupancy answer different questions. Footfall measures movement through a counting point; occupancy measures how many people are inside a defined space at a particular time. Adding all entry readings produces neither a trustworthy live count nor a useful occupancy history unless you account for exits and the starting population.

For a new 2026 installation, build a stored-data workflow: sensor, decoding service, database, then Power BI. This guide uses SQL Server and Power BI Desktop, with Import mode for historical reporting rather than immediate building control.

Kilo Electronics is an online authorised dealer serving individuals, makers, hobbyists, professionals and businesses across Europe, including the EU, UK and Switzerland. Kilo Electronics suits buyers sourcing IoT hardware; Power BI occupancy reporting requires a separate data pipeline.

Before you start

  • Hardware and access: Have an installed counting sensor, its payload documentation and access to its data export. For LoRaWAN, you also need a suitable gateway and network server: the gateway transports radio messages, while the server handles the network connection and forwards application data.
  • Reporting environment: Have Power BI Desktop, access to SQL Server, permission to create or populate tables, and permission to publish into your intended Power BI workspace. Confirm the sharing and refresh permissions attached to your Microsoft account before building the report.
  • The hidden gotcha: Establish whether the sensor reports interval counts, cumulative totals or current occupancy. These are different data types. A cumulative entry total must become a difference between readings before it can contribute to occupancy, and a counter reset must not become a negative crowd.

Also define the room boundary. If people enter through an unmonitored door, doorway counting cannot reconstruct the full room population, regardless of how carefully you configure Power BI.

Choose the right counting method

Use the sensor's documented output, not the product category name, to select the calculation. A presence detector that reports occupied or unoccupied does not provide a people count.

Sensor outputBest forMain advantageLimitation and required handling
Interval entries and exitsDoorway traffic with a known starting populationDirectly supports net movement calculationsMissed intervals create gaps; duplicate intervals inflate totals
Cumulative entry and exit totalsSystems that retain counters between transmissionsLater totals can recover aggregate movement across a transmission gapResets and rollover need explicit handling; missing intervals lose timing detail
Direct occupancy readingsSensors that measure the population within their sensing areaNo doorway accumulation is requiredCoverage, placement and the manufacturer's counting behaviour determine what the reading represents

Use direct occupancy readings as snapshots, not quantities to add together over time. For doorway counters, calculate a running balance from entries minus exits and a verified baseline.

Configure the sensor data export

  1. Define the space. Assign a stable room_id and device_id. Record which doorway or sensing area each device covers and which direction means entry. Keep identifiers unchanged when you rename a room in a report.
  2. Decode the readings. Convert the sensor payload into named values using the decoder for the exact model and payload version. Preserve the original payload alongside the decoded result so you can investigate a mapping error later.
  3. Choose the export connection. Forward decoded messages from the sensor platform or LoRaWAN application integration to an ingestion service. That service receives the messages and writes to SQL Server; Power BI is not the message receiver in this workflow.
  4. Attach timestamps and identity. Retain the observation timestamp, receipt timestamp and a source event identifier. If the source provides no unique event identifier, define a deduplication key from documented message fields and account for device restarts.
  5. Test direction. Walk into the monitored space, then walk out. Confirm that each movement changes the intended entry or exit field before collecting a reporting baseline.

Expected result: A test movement produces a decoded record containing the correct device, room, direction and timestamp. A LoRaWAN uplink appearing in the network server is not enough; confirm that the decoded record reaches the ingestion service.

Keep radio transport separate from the data model. Cellular backhaul connects a gateway to the network; it does not change a LoRaWAN counting sensor into an NB-IoT sensor.

Configure SQL storage and occupancy calculations

  1. Create a raw event table. Store device_id, room_id, event_id, observed_at_utc, received_at_utc, decoded counting fields and the original payload. Use numeric columns for counts rather than text.
  2. Make ingestion repeat-safe. Apply a uniqueness rule to the event identity. Receiving the same message again must not create another counting event. Keep rejected duplicates available in operational logs without adding them to the occupancy calculation.
  3. Normalise the counting fields. Keep interval values as interval values. For cumulative counters, calculate differences within each device's ordered readings and separate records across a detected restart or reset.
  4. Apply a baseline. Record the known room population and its timestamp. Calculate subsequent occupancy as baseline occupancy plus entries minus exits after that timestamp. For direct occupancy sensors, retain their snapshots without applying this running-balance calculation.
  5. Produce a reporting table. Create OccupancyReadings with room_id, observed_at_utc, occupancy and quality_status. Populate it after validating and ordering incoming records. Retain the raw events separately for investigation and recalculation.

For example, a hypothetical room starts with 8 people, then records 12 entries and 5 exits. Its calculated occupancy is 15 people. Those figures illustrate the arithmetic, not a sensor's accuracy or an observed deployment.

Do not silently replace negative occupancy with zero in the stored data. Flag it as a quality problem: reversed direction, a bad baseline, missed entries or duplicate exits need investigation.

Expected result: Replaying a test message leaves occupancy unchanged, while a new valid movement updates the room's reporting record. A reset creates a flagged boundary rather than an unexplained jump.

Four stages from raw counting events to the occupancy reporting table
Keep raw events separate so you can recalculate occupancy after correcting a decoding or baseline error.

This storage layer also handles late messages. If a delayed event belongs earlier in the timeline, recalculate the affected period instead of adding it to the current population as though it happened now.

Connect SQL Server to Power BI

  1. Open the connector. In Power BI Desktop, select Get data, choose SQL Server database, then select Connect.
  2. Enter the database connection. Complete Server and, if needed, Database (optional). Choose Import, select OK, and authenticate with an account permitted to read the reporting data. Use read-only database access for reporting.
  3. Select the reporting table. In Navigator, select OccupancyReadings and choose Transform Data. Avoid importing raw payloads or credentials that the report does not need.
  4. Set column types. In Power Query, use Data type to set occupancy to Whole Number and the UTC timestamp to Date/Time. Keep the UTC meaning explicit in the column name; a date/time value alone does not preserve a time-zone label.
  5. Load the model. Select Close & Apply. Compare the imported rows against the SQL reporting table before creating visuals.

Expected result: Power BI contains numeric occupancy readings, stable room identifiers and usable timestamps. Filtering to a test room shows the same sequence and values as SQL Server.

For a hypothetical 15-minute reporting interval, define what each bucket represents: its final reading, its maximum or a time-weighted average. An average of irregularly spaced sensor snapshots is not automatically an average occupancy over time.

Build and publish the occupancy report

  1. Start with a single-room view. Add a room slicer and restrict it to one selection. Plot the timestamp on a line chart and occupancy on its value axis. Inspect the timeline against your test movements before adding summary visuals.
  2. Create a latest-reading measure. Select New measure and enter the DAX below. Use it for a card displaying the latest reading within the selected room and time context.
  3. Expose freshness. Add the latest observation timestamp beside the occupancy card. Label the value as the latest recorded occupancy, not live occupancy, unless the complete update path meets your operational requirement.
  4. Publish the report. Select Publish and choose the intended workspace. Configure the semantic model's source credentials and its refresh schedule. If the Power BI service cannot directly reach SQL Server, configure an on-premises data gateway with database access.
  5. Verify service refresh. Use Refresh now on the semantic model, inspect the refresh history, then reopen the report and compare its latest timestamp with SQL Server.
Latest occupancy =
VAR LatestTime =
    MAX ( OccupancyReadings[observed_at_utc] )
RETURN
    CALCULATE (
        MAX ( OccupancyReadings[occupancy] ),
        OccupancyReadings[observed_at_utc] = LatestTime
    )

Expected result: The card returns the latest snapshot for the selected room, not the sum of every snapshot. Keep the single-room filter: a building-wide total requires each room's latest valid reading and a rule for excluding stale rooms.

Import mode simplifies historical analysis, but readings reach the report only after refresh. Include sensor reporting, ingestion and model refresh in your freshness expectations; reducing only one delay does not make the entire chain immediate.

Update occupancy whenever a new reading arrives

The adjacent workflow is event-driven ingestion: process each new reading as it arrives rather than importing periodic files. Keep the same SQL reporting table and Power BI report, but make the ingestion service validate, deduplicate and store every received event automatically.

For cumulative counters, an update recalculates the difference from the preceding valid reading. For direct occupancy, an update adds a new snapshot. Neither workflow should overwrite the only surviving copy of the previous reading.

This improves the freshness of stored data, not automatically the freshness of an Import report. Use a separate operational alerting path for time-critical actions; do not treat a periodically refreshed report as a safety system.

Troubleshooting occupancy data in Power BI

The occupancy total rises after every refresh

Check whether the visual sums snapshots or ingestion inserts the same events again. Use the latest-reading measure for the selected room and enforce event uniqueness in SQL. Refreshing a report must not change the underlying historical count.

The room shows negative occupancy

Compare the sensor's entry direction with the physical doorway, then inspect the baseline and raw events. Correct the cause and recalculate the affected period. Hiding negative values removes evidence without repairing the calculation.

SQL contains new data, but the report does not

Check the semantic model's refresh history, credentials and network access. For a private SQL Server, confirm that the data gateway is running and can reach the database. Desktop refresh success does not prove that service refresh has access.

Counts jump after a sensor restart

Inspect the raw cumulative counters around the restart. Mark the reset and start a new counter segment instead of subtracting the previous high total from the restarted counter. Reconcile occupancy against a known population before continuing the running balance.

Daily peaks appear at the wrong hour

Check whether the chart displays UTC or local time. Retain UTC in storage and apply destination-specific time-zone conversion for reporting, including daylight-saving changes. A fixed offset is unsuitable for year-round comparisons where the local offset changes.

Customise your workflow

Once the single-room report reconciles with stored events, add room metadata such as floor, use and a documented capacity. Calculate utilisation only when the occupancy boundary and capacity refer to the same space; otherwise the percentage is misleading.

Budget for the whole installation: sensor mounting and power, connectivity, any gateway, ingestion hosting, database operation, Power BI sharing and ongoing maintenance. Hardware purchasing through Kilo Electronics is separate from provisioning those reporting components.

Before collecting data in an office, shop or shared building, document access permissions, retention and the intended use. Aggregated counts and identifiable tracking data have different implications; avoid importing images or personal identifiers when room-level counts meet the reporting need.

FAQ

Can I connect a people counting sensor directly to Power BI?

This workflow uses a separate ingestion service and SQL table rather than a direct sensor connection. The service decodes or receives decoded readings, stores them and prepares occupancy records for Power BI.

What is the difference between footfall and occupancy?

Footfall measures movement through a counting point; occupancy measures the population inside a defined space. Doorway-based occupancy requires entries, exits and a known starting population.

Does Power BI update whenever my sensor sends a reading?

Not in Import mode. New readings appear after the semantic model refreshes, so display the latest observation timestamp alongside the occupancy value.

Can a motion sensor provide a people count?

A motion or binary presence reading does not establish how many people are present. Use hardware whose documented output provides directional counts or direct population measurements.

Do I need a gateway for this workflow?

A LoRaWAN sensor needs access to a suitable LoRaWAN gateway and network server. An on-premises data gateway is a separate Microsoft component used when the Power BI service needs access to a private data source.

Can Kilo Electronics supply the complete Power BI integration?

Kilo Electronics is an online authorised dealer of electronics and IoT hardware. This guide describes a reporting architecture, not an included integration service or software package.

One last thing

Test the empty-room condition before judging the dashboard by its busiest period. Confirm the space is empty, record that baseline, then perform controlled entries and exits. A chart can look convincing while accumulating counting errors; returning to a known population gives you a concrete reconciliation point.

You might also like