HeadlinesBriefing favicon HeadlinesBriefing.com

Auto-Assign Categories in Power Query and DAX

Towards Data Science •
×

In a facility management project, unassigned seats must be categorized by the organizational unit (OU) owning the most seats — first by room, then by floor if a room has no assignments. Data resides in monthly Excel files (e.g., 20260331_Seatlist.xlsx), with only the latest file used for assignments.

The author initially built an M-function in Power Query to find the newest file, read it, group seats by room and floor, count seats per OU, and assign the top owner. This worked locally but failed on network sources: SharePoint loads took over two hours due to latency from row-by-row function execution, and dynamic data sources are blocked in the Power BI Service after publishing.

The solution shifted to DAX. A calculated column flags the newest file using `MAX([File Date])` with `REMOVEFILTERS`. A second column assigns the OU by summarizing the latest dataset per room, filtering out blanks, counting rows per OU, and picking the highest count — falling back to the floor-level owner when needed. This approach avoids network round-trips and publishes successfully.