Sub topic 9
Creating Queries and KPIs as a Key User
This chapter assumes you have read the chapters on analytical query views, measures, and access controls. You should also know the SAP Fiori launchpad, and the terms "cube", "dimension", "rows", "columns" and "authorization check". A key user is a business user with extra rights to adapt the system without writing ABAP code. After this chapter you should be able to build a query from an existing cube in the browser, turn one of its measures into a KPI, and explain what the tools can't do.
Where Key User Tools Fit
In the previous chapters a developer wrote the query view as CDS source code. That approach is flexible, but it needs a developer, a transport request, and a release cycle. Many reporting needs are small. Examples are "net amount by customer for my region" or "open items over 30 days, as a tile".
SAP S/4HANA therefore ships key user tools that run in the Fiori launchpad. They work on the same Virtual Data Model (VDM) you already know. A key user does not build a new data model. The key user picks a released cube or dimension and composes a query on top of it.
| Task | Typical Fiori app | Output |
|---|---|---|
| Find a suitable data source | View Browser | A list of CDS views with their fields, category and annotations |
| Define a custom query | Custom Analytical Queries | A generated query view, stored in the customer namespace |
| Run and explore a query | Query Browser or a report app | An interactive table or chart |
| Define a KPI | Manage KPIs and Reports (the KPI Modeler) | A KPI with target, thresholds and a tile |
| Place the tile | Launchpad content or page and space management | A visible tile for a role |
App names and exact menu labels change between S/4HANA releases. Check the app names and versions in your own system. The ideas in this chapter hold across releases.
The Workflow in One Picture
The query is the foundation. A KPI is a thin layer that points to one measure of a published query and adds meaning to it, such as "good" and "bad" values.
Step 1: Choose a Data Source
Open the View Browser and search for a cube that matches your topic, for example sales items. For each view the browser shows:
- the view name and its VDM type (interface, composite or consumption)
- the data category, which must be cube for most measure-based queries
- the list of fields, with labels and whether each field is a measure
- the associations that bring in dimension attributes
Look at the category before anything else. Our running example ZI_SalesItemCube carries @Analytics.dataCategory: #CUBE, so it can serve as a source. A dimension view such as ZI_CustomerDim can't be the source of a query on its own, because it has no measures to aggregate.
Prefer a source that is already published for reuse. Selecting an internal view that SAP may change creates a maintenance risk. The tool lists only sources that are released for this purpose, which protects you from the worst cases.
Step 2: Create a Custom Analytical Query
In the Custom Analytical Queries app you create a new query and enter three things.
- A label that business users will see.
- A technical name. The tool generates a CDS query view with this name in the customer namespace, so choose a name that follows your naming guidelines.
- The data source from Step 1.
Then you work with the field list. The app divides fields into groups that match the concepts from the query chapter:
| Area in the app | What it controls | CDS equivalent |
|---|---|---|
| Rows | Characteristics that are listed down the side | `@AnalyticsDetails.query.axis: #ROWS` |
| Columns | Measures or characteristics across the top | `@AnalyticsDetails.query.axis: #COLUMNS` |
| Free characteristics | Fields hidden at first, which a user can drag in at run time | `@AnalyticsDetails.query.axis: #FREE` |
| Filters | Preselected or mandatory limits | `@Consumption.filter` |
Measures keep the aggregation defined in the cube. For NetAmount, @DefaultAggregation: #SUM is part of the cube, so the key user does not choose it and can't turn a sum into an average. The currency link @Semantics.amount.currencyCode: 'Currency' also stays in force. When you list NetAmount by customer, amounts in different currencies are not added together. The result splits by currency, or it shows a mixed-currency marker, as the front end defines.
What the Generated Query Corresponds To
The tool writes CDS for you. Here is the kind of source a developer would write to get a comparable result. Compare it with the query view from the earlier chapter.
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Net amount by customer and country'
@Analytics.query: true
define view entity ZC_NetAmountByCustCountry
as select from ZI_SalesItemCube
{
@AnalyticsDetails.query.axis: #ROWS
CustomerId,
@AnalyticsDetails.query.axis: #FREE
_Customer.Country as CustomerCountry,
@Consumption.filter: { selectionType: #RANGE, multipleSelections: true }
@AnalyticsDetails.query.axis: #FREE
Currency,
@AnalyticsDetails.query.axis: #COLUMNS
NetAmount
}The country comes from the dimension through the association _Customer, which the cube exposes. That is why a key user can use the field "Country" even though it is not a column of the sales table. The tool lists fields reachable through exposed associations next to the cube's own fields.
Filters and Free Characteristics
Use a fixed filter for a limit that must always apply, such as "company code 1000". Use a selection filter for something the report user may change, such as a date range. Put detail fields in the free characteristics, not in the rows. A report with 15 row fields is slow to read, and it forces the database to build a very granular result before aggregating. A short default layout with many fields available on demand performs better.
Step 3: Test and Publish
Use the preview in the app to check three things before you publish.
- Totals. Compare the result with a known figure, for example a value from a classic transaction report.
- Currency and unit handling. Check that mixed currencies are not silently summed.
- Authorization effect. Test with a user who has narrower rights, if you can.
Publishing makes the query available to other tools. The query behaves like any query view. It can be used in a Fiori report app, in a KPI, or through an analytical service that other front ends consume, if the query is enabled for that.
Step 4: Define a KPI
A KPI (key performance indicator) is a single measure of a query, shown with a judgment: is the value good, a warning, or critical? In the KPI tool you define:
- The data source. This is a published query, plus the measure to evaluate.
- Filters. These are limits that apply only to this KPI, for example "current fiscal year". A KPI may be filtered more narrowly than the query.
- Improvement direction. Choose maximize (higher is better, such as revenue), minimize (lower is better, such as overdue payments), or target (close to a goal is best, such as stock level).
- Thresholds. These are the values at which the status changes. For maximize, you set the values below which the result is critical and below which it is a warning. For minimize the thresholds are upper limits.
- Target and trend. The target is a reference value, and the trend compares the current value with a previous period.
The tile shows the status through colors. Red, yellow and green are the usual choices. A colorblind user also needs the number and the trend arrow, so don't rely on color alone when you describe a KPI in documentation.
Here is a worked example for the running data model.
| Setting | Value |
|---|---|
| Query | Net amount by customer (published) |
| Measure | `NetAmount` |
| Filter | Fiscal year equals current year |
| Direction | Maximize |
| Warning below | 800,000 |
| Critical below | 500,000 |
| Target | 1,200,000 |
A tile that shows 650,000 is in warning status, because it is below 800,000 but not below 500,000. Define the thresholds as numbers in one currency. If the measure can occur in several currencies, add a filter for the reporting currency. Otherwise the KPI can't compare the figure with the threshold.
Drill-Down from the Tile
A tile alone shows only one number. When you configure the KPI, you can link it to a target such as a report or a query-based drill-down. A user then clicks the tile and moves from "650,000, warning" to the table of customers behind the number. Because the target uses the same query, the total in the table matches the figure on the tile.
Step 5: Publish the Tile
A KPI tile becomes visible only after it is assigned. This is the step most often forgotten. In the launchpad configuration the tile is placed in a catalog or a page and space, and it is released to a role. Users who do not have that role do not see the tile. This is a visibility setting. It does not change authorization on the data. A user who has the tile but no authorization for the data sees only the part of the data they are allowed to read.
Common Errors
| Symptom | Likely cause | Remedy |
|---|---|---|
| The cube is missing from the data source search | The view is not a cube, or it is not released for this use | Check its category and release status in the View Browser |
| A needed field is not selectable | The cube does not expose it | Ask for a custom field or a cube extension |
| Totals differ between two users | Different authorizations | Compare their roles. Don't change the query |
| The KPI shows "no data" | A filter is too narrow, or the period has no data | Test the same filter in the query preview |
| The KPI status looks wrong | Wrong improvement direction or reversed thresholds | Check that the thresholds fit *maximize* or *minimize* |
| Colleagues can't find the tile | The tile is not assigned to a catalog, page or role | Assign it in the launchpad configuration |
| The report is slow | Too many fields on the rows, or no mandatory filter | Move detail fields to free characteristics and add a date filter |
Limits and Decision Criteria
Key user tools are the right choice when the cube already contains what you need, and the change is a different arrangement of fields, a filter, or a KPI. A developer-built query is the better choice in these cases:
- You need logic that the tool can't express, such as complex calculations or special currency conversion.
- The query is a standard for many teams, and it needs version control and a transport through the landscape.
- The cube must be extended with new joins or new measures.
A good habit is to let key users prototype, then decide whether a successful query should move into the developer's code base.
Exercise
A key user creates a query on a cube that has a net amount in several currencies and defines a KPI tile with the "maximize" direction and a warning threshold of 800,000. The tile shows a value in warning status for user A. User B sees a lower value and a red tile for the same KPI. Give two causes that don't involve a defect, and name one change to the KPI definition that makes the comparison against the threshold reliable.
Show answer
First, user B may have narrower authorizations, so the cube's access control returns fewer rows and a lower total. Second, the KPI may mix currencies, so each user's total can differ depending on which currencies their data contains. To make the threshold comparison reliable, add a filter for a single reporting currency to the KPI, and express the thresholds in that currency.
Exercise
Why can a key user not change the aggregation of NetAmount from sum to average in a custom analytical query, and what kind of user would change it?
Show answer
The aggregation is defined in the cube through the annotation @DefaultAggregation: #SUM. The custom query inherits it. A developer who owns the cube changes it in the CDS source, if that is correct for the measure.