Data Analysis View
1. What is a View?
Within Mitra components, the "View" defines the database data that will feed the component. The View can be configured in three ways: Data Analysis View, Registration View (both no-code), or SQL View. In this documentation, we will focus on the Data Analysis View, which allows you to return database data in a no-code manner, simplifying complex queries.
2. Structure of the Data Analysis View
The Data Analysis View is mainly composed of "Data" and "Groupers":
Data: Represents the columns of the query. For example, sales value can be considered as data.
Groupers: Determine how the data will be organized. For example, "Sales by Salesperson" — the data would be "Sales" and the grouper would be "Salesperson".
3. Data Types
Data in the View can be of two types: "Attribute" or "Function."
3.1. Attribute
Attributes can be divided into two categories: "Standard Attribute" or "FK Attribute."
3.1.1. Standard Attribute
A "Standard Attribute" is a value extracted directly from the database and can be of type "Numeric," "Text," or "Date".
Here are the main functionalities associated with standard attributes:
Aggregation Function: Choose how the data will be aggregated (sum, count, average, etc.).
Data Entry: Allows the user to input values directly into the table. Data entry is only possible if the data is at the most granular level of the query (e.g., sales by month). If the data is at an aggregated level (e.g., sales by year), data entry will not be possible. For more information, refer to the "Data Entry" documentation.
Offset: Use the "Offset" to compare data from different periods. Example: compare sales of the current month with those of the same month last year using an offset of -12 months. Granularity can be defined as days, weeks, months, quarters, or years.
Additional Filters: Apply filters directly to the data, in addition to the general View filters. Example: view sales from different curves in separate columns. As shown below, in the first column, view sales from "Curve A," in the second column, "Curve B," and in the third column, "Curve C."
Conditional Formatting (tables only): Modify the appearance of cells based on conditions. Example: Color the cells blue if sales are above R$100,000, yellow between R$80,000 and R$100,000, and red below R$80,000.
3.1.2. FK Attribute
An "FK Attribute" (Foreign Key) displays related tables for a grouper.
Relationship with Grouper: The FK attribute can only be used if there is a related grouper. Example: If the grouper is "Salesperson," you can add an FK Attribute to display the "Sales Manager" related to that salesperson.
Data Entry with FK Attribute: One of the most interesting uses of an FK Attribute is to allow relationship changes directly in the View. For example, in a table of salespeople, you can allow the user to change the relationship between the salesperson and their manager if data entry is enabled. For more information, refer to the "Data Entry" documentation.
Additional FK Attribute Use: When you want to use the description or code of the grouper for specific functions. For example, suppose you want to create a function where all salespeople with an ID less than 3 are classified as "2," and those with an ID greater than 3 are classified as "1." In this case, you can bring the grouper ID or description as an "FK Attribute" and then use it within the function to define the criteria as needed. This criterion can be used, for example, in a column filter or even displayed directly to the user as a calculated value within the table.
3.2. Function
A "Function" allows you to create calculations or manipulate data directly within the View. Functions can be simple, such as adding or dividing data, or complex, using JavaScript expressions.
Here are the main functionalities of a Function:
Mathematical Expressions: Use functions to perform calculations between data. Example: A / B, where A is sales value and B is sales quantity.
Concatenating Values: In Mitra, to concatenate data with strings, the syntax used is the addition operator (+). Example: A + ' is greater than ' + B would concatenate the value of A with the text "is greater than" and the value of B.
Conditional IF: The "IF" in Mitra follows the structure:
A > 100 ? 1 : 0
Explanation: If A is greater than 100, the result will be 1; otherwise, it will be 0.
Advanced Manipulation with JavaScript: In addition to basic calculations, you can use JavaScript to create more complex manipulations. Examples:
Math.round(A)
Explanation: Rounds the value of A.
A + B
Explanation: Concatenates two values.
Special Function - _old: The _old operator allows you to compare the value of a data point with the value of the same data point in the previous row. This is useful for trend analysis, such as comparing current month sales with the previous month. Example: A - A_old, where A is current sales, and A_old is the previous month's sales.
4. Groupers
By default, the grouper description is displayed, but you have the option to customize this display. You can choose to show only the description, display only the grouper code, or display both (code followed by the description). This flexibility allows you to adjust the data presentation according to the context and visualization needs, making the display more informative or simplified as required.
5. Filters
The Data Analysis View allows you to apply filters at both the screen level and within the View itself.
Screen Filters: The View automatically respects the filters applied to the screen.
Additional Filters: You can apply specific filters within the View, in addition to the global screen filters. Example: Filter online sales while the screen displays both online and offline.
Column Filter: Allows filtering the values of a specific column.
6. Sorting
You can define the sorting of data in the View in different ways:
Data Sorting: Example, sort sales in descending order.
Grouper Sorting: Example, sort salespeople in alphabetical order.
7. Show All Configuration
The "Show All" option is used to display all members of a grouper, even if they have no value in the data.
Example Use Case: When entering data and you want to see all products, even those without sales, the Show All option will be useful. For data analysis, you typically do not want to see groupers without value, but for data entry, this option can be essential.
8. Record Limit and Formatted Report
You can limit the number of records returned and also mark the View as a "Formatted Report." For more details, see the "Formatted Report" documentation.