on 2024 Jul 09 1:12 AM
There is graph in this Fiori app which is displayed on the basis of CDS annotations @ui.chart.measures in CDS view.
The issue is the graph created from CDS view using annotation @ui.chart.measures takes by default the SUM of all the values of the field associated with @ui.chart.measures.
However, our requirement is that the graph should consider the AVERAGE of the field associated with @ui.chart.measures.
Request clarification before answering.
There is an example, please check and test.
---
1. **Calculate the Average in the CDS View:**
To start, you need to modify your CDS view to calculate the average value instead of the sum. You can achieve this by using SQL functions in HANA CDS views. Here's an example of what your CDS view might look like:
```abap
@AbapCatalog.sqlViewName: 'ZMY_CDS_VIEW'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'CDS View for Average Calculation'
define view ZMY_CDS_VIEW as select from your_table
{
key field1,
key field2,
field3, // Some other fields that might be necessary
avg(your_measure_field) as average_field
}
group by
field1,
field2,
field3
```
In this example, replace `your_table` with the actual table name and `your_measure_field` with the field for which you need to calculate the average.
2. **Use the Correct Annotation:**
Now, you need to annotate this calculated field `average_field` appropriately in the CDS view so that it is picked up in the Fiori app.
```abap
@AbapCatalog.sqlViewName: 'ZMY_CDS_VIEW'
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'CDS View for Average Calculation'
define view ZMY_CDS_VIEW as select from your_table
{
key field1,
key field2,
field3, // Some other fields that might be necessary
@ui.chart: [{
chartType: #COLUMN,
axis1: #CATEGORY,
axis2: #VALUE,
measures: ['average_field'],
dimensions: ['field1', 'field2']
}]
avg(your_measure_field) as average_field
}
group by
field1,
field2,
field3
```
Ensure that the `measures` annotation inside the `@UI.chart` reflects the calculated average field.
3. **Update Your Fiori App:**
Finally, you need to check that the Fiori app is configured to use the correct metadata
---
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 6 | |
| 6 | |
| 6 | |
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 3 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.