Comments (4)
Hi @MadhusudanN 👋 Thanks for a very detailed and thorough question!
So I notice the Cube UI is the one which is handling the missing data and showing it as 0 where data is missing from the backend. Can some one please confirm on this behaviour.
Your conclusion is exactly correct. Let me explain what is happening here:
- As you were able to confirm yourself, Cube's APIs (REST, SQL, etc.) return query results as they are. If there's no measure value(s) for a particular time dimension value, it would not be present in the result set, as you would expect.
- Cube's JavaScript SDK (a set of tools to help integrate Cube's APIs with front-end applications) "fills missing dates" by default (see the
fillMissingDates
option ofPivotConfig
). Such defaults generally makes sense because embedded analytics applications usually put data on charts. There's also an option to override these defaults withfillMissingDates: false
. - Cube's Playground uses Cube's JavaScript SDK and inherits these defaults.
I hope it clarifies things.
Is it something that renders Playground unusable for you?
from cube.
Hi @igorlukanin Thanks a lot for the reply. It is clear.
I have one question regarding the support for Fiscal Year, Fiscal Quarter etc. in the time dimension.
For example if we need to get sales total based on Fiscal Quarter, do we have support for that in cube.
Please see the screenshot below for illustration.
Can you please let me know is there a way we can achieve this with Cube.
from cube.
@MadhusudanN Sure! Just FYI, there's an open discussion about fiscal year support in date calculations that you can join.
However, in your particular use case, a very viable and working approach would be to define a separate dimension for the fiscal quarter and use it in your queries. Consider the following data model that defines such a dimension for Australia, where FY2024-Q1 starts in July 2024:
cubes:
- name: fiscal
sql: >
SELECT '2024-01-15T00:00:00.000Z'::TIMESTAMP AS timestamp UNION ALL
SELECT '2024-02-15T00:00:00.000Z'::TIMESTAMP AS timestamp UNION ALL
SELECT '2024-03-15T00:00:00.000Z'::TIMESTAMP AS timestamp UNION ALL
SELECT '2024-04-15T00:00:00.000Z'::TIMESTAMP AS timestamp UNION ALL
SELECT '2024-05-15T00:00:00.000Z'::TIMESTAMP AS timestamp UNION ALL
SELECT '2024-06-15T00:00:00.000Z'::TIMESTAMP AS timestamp UNION ALL
SELECT '2024-07-15T00:00:00.000Z'::TIMESTAMP AS timestamp UNION ALL
SELECT '2024-08-15T00:00:00.000Z'::TIMESTAMP AS timestamp UNION ALL
SELECT '2024-09-15T00:00:00.000Z'::TIMESTAMP AS timestamp UNION ALL
SELECT '2024-10-15T00:00:00.000Z'::TIMESTAMP AS timestamp UNION ALL
SELECT '2024-11-15T00:00:00.000Z'::TIMESTAMP AS timestamp UNION ALL
SELECT '2024-12-15T00:00:00.000Z'::TIMESTAMP AS timestamp
dimensions:
- name: timestamp
sql: timestamp
type: time
- name: fiscal_year_internal
sql: "EXTRACT(YEAR FROM {timestamp} - INTERVAL '6 MONTH')"
type: string
public: false
- name: fiscal_quarter_internal
sql: >
CASE
WHEN EXTRACT(MONTH FROM {timestamp}) BETWEEN 7 AND 9 THEN 1
WHEN EXTRACT(MONTH FROM {timestamp}) BETWEEN 10 AND 12 THEN 2
WHEN EXTRACT(MONTH FROM {timestamp}) BETWEEN 1 AND 3 THEN 3
WHEN EXTRACT(MONTH FROM {timestamp}) BETWEEN 4 AND 6 THEN 4
END
type: string
public: false
- name: fiscal_quarter
sql: "'FY' || {fiscal_year_internal} || '-Q' || {fiscal_quarter_internal}"
type: string
Here's what you'll get querying the fiscal_quarter
dimension:
![Screenshot 2024-01-04 at 11 44 26](https://private-user-images.githubusercontent.com/3852894/294157174-655f8ca7-d6d2-4750-ad6e-a82a0578b9fd.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MDcxNDY2NzQsIm5iZiI6MTcwNzE0NjM3NCwicGF0aCI6Ii8zODUyODk0LzI5NDE1NzE3NC02NTVmOGNhNy1kNmQyLTQ3NTAtYWQ2ZS1hODJhMDU3OGI5ZmQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDIwNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDAyMDVUMTUxOTM0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NzdmZDczZDJiMzFkNTM1YzZhZThiYjE3M2JiYzE1NGRlM2VmNmY5MGFiNjFjZDBjNGJiN2M2ZWZmMWZhMzRlMiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.xMLtdEI9qkISGl3BjGOWvla2Fef4EqxUg3pKjfKwpbE)
Note that fiscal_year_internal
and fiscal_quarter_internal
would need to be adjusted to the fiscal calendar that you'd like to use because different fiscal calendar schemes use different month offsets.
I hope it helps 😊
from cube.
FYI, I've extracted my comment into this recipe: https://cube.dev/docs/guides/recipes/data-modeling/fiscal-year-quarter-dimensions
from cube.
Related Issues (20)
- "Please consider reducing total number of partitions by using rollup_lambda pre-aggregations" question
- When Cubestore Router container is recreated, all pre-aggregations get rebuilt HOT 2
- Wrong join order HOT 1
- localization of the entire text HOT 1
- Dynamic table name 动态表名
- Submeasures of calculated measures not wrapped in brackets HOT 1
- When using Cubestore with a remote dir that is backed by Azure Blob Storage, an extremely high number of List operations are executed per day HOT 1
- Feedback for “Deploying Cube Core with Docker” HOT 1
- Excessive "Skip processing" log message -- what does it mean? HOT 1
- How to get meta information in the Cube model through the SQL API, just like the annotation field information returned in the REST API
- Cannot parse complex SQL WHERE clauses including `false` HOT 1
- Packages Error when serve build, but ok in dev mode
- Pre-aggregations with elasticsearch as datasource are not timezone aware HOT 1
- Option to hide the few critical information from the cube response like dataSource, dbType and extDbType
- Preaggregations partitions are only built for query dateranges instead of the partition granularity. HOT 2
- Support for IntelliJ clients (datagrip/pycharm)
- ResultSet returned by subscribe() in production mode is different from dev mode
- Need to define a cube based on a Postgre sql User defined function with string parameter HOT 3
- Request for an Official & Maintained Helm Chart HOT 1
- Trigger pre-aggregation build jobs via /v1/pre-aggregations/jobs REST API no more working from version 0.34.44.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cube.