Hi,
I needed help for my Defender for Cloud workbook. The following KQL allows me to show the selected custom policies or initiatives (from Control parameter) in a table. Unfortunately, I am unable to figure out how to improve the KQL to show the data from compliance policy on the complianceState, resourceCompliance, nonCompliantResources etc.
Kindly refer to screenshot 1 which is the table generated by this KQL.
![User's image](https://learn-attachment.microsoft.com/api/attachments/6019169d-4562-4e42-a2e5-893197fbee4c?platform=QnA)
But, I can see the data fine in the Policy | Compliance on the Compliance state, Resource compliance, non-compliant resources and non-compliant policies.
So how can I pull the data from Policy | Compliance into this table, so that it shows exactly like how it being displayed in Policy | Compliance?
Thank you so much
PolicyResources
| where type in ("microsoft.authorization/policydefinitions", "microsoft.authorization/policysetdefinitions") // Policy Definitions and Initiatives (Policy Sets)
| extend
displayName = tostring(properties.displayName),
Type = case(type == "microsoft.authorization/policydefinitions", "Policy",
type == "microsoft.authorization/policysetdefinitions", "Initiative",
"Unknown"), // Determine if it's a Policy or Initiative
category = tostring(properties.metadata.category),
complianceState = tostring(properties.complianceState), // Fetch compliance state
resourceCompliance = strcat(tostring(properties.complianceSummary.compliantResources), " out of ", tostring(properties.complianceSummary.totalResources)), // Calculate resource compliance
nonCompliantResources = tostring(properties.complianceSummary.nonCompliantResources), // Fetch non-compliant resources
nonCompliantPolicies = tostring(properties.complianceSummary.nonCompliantPolicies) // Fetch non-compliant policies
| where displayName in ({Control}) // Filter by selected custom initiatives/policies
| project subscriptionId, displayName, Type, category, complianceState, resourceCompliance, nonCompliantResources, nonCompliantPolicies
| order by displayName asc