-
Notifications
You must be signed in to change notification settings - Fork 158
FOCUS query library #1401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
flanakin
wants to merge
1
commit into
dev
Choose a base branch
from
flanakin/dev/focus-queries
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
FOCUS query library #1401
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
--- | ||
title: FOCUS query library | ||
description: Collection of SQL and KQL queries that leverage the FinOps Open Cost and Usage Specification (FOCUS). | ||
author: flanakin | ||
ms.author: micflan | ||
ms.date: 03/11/2025 | ||
ms.topic: concept-article | ||
ms.service: finops | ||
ms.subservice: finops-learning-resources | ||
ms.reviewer: micflan | ||
#customer intent: As a FinOps user, I want to query FOCUS data. | ||
--- | ||
|
||
<!-- markdownlint-disable-next-line MD025 --> | ||
# FOCUS query library | ||
|
||
This article outlines a collection of SQL and KQL queries that can be used with a data store that hosts FinOps Open Cost and Usage Specification (FOCUS) data. Use the queries here to explore your data in [Microsoft Fabric](../fabric/create-fabric-workspace-finops.md) or [FinOps hubs](../toolkit/hubs/finops-hubs-overview.md) with Data Explorer. | ||
|
||
<br> | ||
|
||
## Prerequisites | ||
|
||
Before you can execute these queries, you must have: | ||
|
||
- A KQL or SQL database, like Azure Data Explorer or a Microsoft Fabric lakehouse or eventhouse. | ||
- Create a table named "Costs" that uses a FOCUS 1.0 schema. | ||
- Ingest cost from Microsoft and optionally other cloud or SaaS providers based on your needs. | ||
|
||
If you do not have a database, consider one of the following options: | ||
|
||
- [FinOps hubs](../toolkit/hubs/finops-hubs-overview.md) with Data Explorer | ||
- [Microsoft Fabric lakehouse](../fabric/create-fabric-workspace-finops.md) | ||
|
||
<br> | ||
|
||
## Account structure | ||
|
||
Different providers have different account constructs that FinOps practitioners use for allocation, reporting, and more. Organizations may have one or many accounts within one or more providers and FinOps practitioners may need to review the cost broken down by each account. FOCUS has two types of accounts: a billing account and a sub account. | ||
|
||
A billing account is the account where invoices are generated. Each billing account can have one or more sub accounts, which can be used for deploying and managing resources and services. Billing and sub accounts are often used to facilitate allocation strategies and FinOps practitioners must be able to break costs down by billing and sub account to facilitate FinOps scenarios like chargeback and budgeting. | ||
|
||
### Example: Cost breakdown by account | ||
|
||
**KQL** | ||
|
||
```kusto | ||
Costs | ||
| where BillingPeriodStart == startofmonth(now(), -1) | ||
| summarize | ||
BillingAccountName = take_any(BillingAccountName), | ||
BillingAccountType = take_any(BillingAccountType), | ||
SubAccountName = take_any(SubAccountName), | ||
SubAccountType = take_any(SubAccountType), | ||
BilledCost = sum(BilledCost) | ||
by | ||
BillingAccountId, | ||
SubAccountId | ||
``` | ||
|
||
**SQL** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we avoid overlaps with the FinOps Foundation's Use Case Library? Will that library be populated with Frequently Asked Queries? |
||
|
||
```sql | ||
SELECT | ||
BillingAccountId, | ||
BillingAccountName, | ||
BillingAccountType, | ||
SubAccountId, | ||
SubAccountName, | ||
SubAccountType, | ||
SUM(BilledCost) | ||
FROM Costs | ||
WHERE BillingPeriodStart = DATEADD(month, -1, DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0)) | ||
GROUP BY | ||
BillingAccountId, | ||
SubAccountId | ||
``` | ||
|
||
<br> | ||
|
||
## Give feedback | ||
|
||
Let us know how we're doing with a quick review. We use these reviews to improve and expand FinOps tools and resources. | ||
|
||
> [!div class="nextstepaction"] | ||
> [Give feedback](https://portal.azure.com/#view/HubsExtension/InProductFeedbackBlade/extensionName/FinOpsToolkit/cesQuestion/How%20easy%20or%20hard%20is%20it%20to%20use%20the%20Implementing%20FinOps%20guide%3F/cvaQuestion/How%20valuable%20is%20the%20Implementing%20FinOps%20guide%3F/surveyId/FTK0.8/bladeName/Guide.FOCUS/featureName/Queries) | ||
|
||
If you're looking for something specific, vote for an existing or create a new idea. Share ideas with others to get more votes. We focus on ideas with the most votes. | ||
|
||
> [!div class="nextstepaction"] | ||
> [Vote on or suggest ideas](https://github.com/microsoft/finops-toolkit/issues?q=is%3Aissue+is%3Aopen+sort%3Areactions-%252B1-desc) | ||
|
||
<br> | ||
|
||
## Related content | ||
|
||
Related resources: | ||
|
||
- [FinOps Framework](../framework/finops-framework.md) | ||
|
||
Related products: | ||
|
||
- [Azure Carbon Optimization](/azure/carbon-optimization/) | ||
- [Azure Advisor](/azure/advisor/) | ||
- [Azure Resource Graph](/azure/governance/resource-graph/) | ||
|
||
Related solutions: | ||
|
||
- [FinOps toolkit Power BI reports](../toolkit/power-bi/reports.md) | ||
- [FinOps hubs](../toolkit/hubs/finops-hubs-overview.md) | ||
- [FinOps workbooks](../toolkit/workbooks/finops-workbooks-overview.md) | ||
- [Optimization engine](../toolkit/optimization-engine/overview.md) | ||
|
||
<br> |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
take_any is random. arg_max() would be the better choice (return the latest BillingAccountName for the BillingAccountId) but that would make the query even less readable.