Category / Section
How to Retrieve Previous Quarter Data in Bold BI
Published:
In Bold BI, it is possible to retrieve previous quarter data and calculate the percentage change without writing complex SQL queries. This can be achieved using the expression syntax provided for PostgreSQL, MS SQL Server, and MySQL.
Steps to Retrieve Previous Quarter Data
-
Add Expression: Click on the ‘Add Expression’ button to start creating an expression.
-
Create Expression: Create an expression to get freight values based on the current quarter and the previous quarter.
Syntax of Expressions
For PostgreSQL and all extract and rest data sources:
- Freight- Previous Quarter:
IF(Extract (Quarter from [Date]) = Extract(Quarter from DATESUB(90, TODAY())) AND YEAR([Date])=YEAR(DATESUB(90, TODAY())), [Freight], 0)
- Freight- Current Quarter:
IF(Extract (Quarter from [Date]) = Extract(Quarter from TODAY()) AND YEAR([Date])= CURRENTYEAR(), [Freight], 0)
For SQL Server:
- Freight- Previous Quarter:
IF(DATEPART(Quarter, [Date]) = DATEPART(Quarter, DATESUB(90, TODAY())) AND YEAR([Date])=YEAR(DATESUB(90, TODAY())), [Freight], 0)
- Freight- Current Quarter:
IF(DATEPART(Quarter, [Date]) = DATEPART(Quarter, TODAY()) AND YEAR([Date])=CURRENTYEAR(), [Freight], 0)
For MySQL:
- Freight- Previous Quarter:
IF(Quarter([Date]) = Quarter(DATESUB(90, TODAY())) AND YEAR([Date])=YEAR(DATESUB(90, TODAY())), [Freight], 0)
- Freight- Current Quarter:
IF(Quarter([Date]) = Quarter(TODAY()) AND YEAR([Date])=CURRENTYEAR(), [Freight], 0)
- Create KPI Expression: Create a KPI expression in widget properties for getting percentage values.
This will allow you to see the percentage difference between the previous and current quarter.