Fix unattached disks report showing all disks instead of only unattached disks #1858
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The optimization dashboard's unattached disks report was incorrectly showing all disks (540 in the reported case) instead of only the unattached disks (16 expected). This made the optimization recommendations unusable and inflated cost-saving estimates.
Root Cause
The Storage workbook's unattached disks query used an
inneruniquejoin to filter disks by optional tag parameters. When users didn't select tag filters (TagName and TagValue were null/empty), the join condition behaved unexpectedly:With
inneruniquejoin semantics, only rows matching on both sides are returned. When tag parameters are null, the filter condition fails to properly handle the empty case, causing either all disks to be filtered out or incorrectly included.Solution
Changed the join from
inneruniquetoleftouterand added conditional logic to only apply tag filtering when the parameters are actually set:innerunique→leftouterto preserve all unattached disks regardless of tag matchingwhere isnotempty('{TagName}') and ...in the join subquery to only filter by tags when TagName parameter is setwhere isempty('{TagName}') or isnotnull(DiskId1)to include all disks when no tag filter is active, or only matched disks when tags are specifiedproject-away DiskId1to remove the duplicate column from the joinBehavior
Before: Shows all disks (540) when no tag filter is selected ❌
After: Shows only unattached disks (16) when no tag filter is selected ✅
Tag filtering continues to work when users select specific tags, while the default view (no tags selected) now correctly shows only unattached disks.
Testing
This fix follows Azure Workbooks best practices for handling optional parameters as documented in Workbook dropdown parameters and KQL conditional filtering.
Fixes #[issue_number]
Original prompt
Fixes #1818
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.