Articles in this section
Category / Section

How to Filter Data from the Past 5 Years Using a Custom SQL Query in Bold BI®

Published: Jun 19, 2024

Overview:

We can filtering data to show information from the past five years for a specific date can be achieved in Bold BI® by using a custom SQL query. This guide provides a detailed step-by-step process to set up this functionality using a date picker widget.

Steps to Filter Data from the Past 5 Years:

Step 1: Create a Data Source and Import Dataset

Begin by creating a data source, which could be from various sources such as Excel, a database, etc. Import your dataset into Bold BI® and save it as “Datasource1”. Within Datasource1, create a dashboard parameter, which will be a date parameter that users can select or input to define the specific date for which the past five years of data is needed.

screenshot1.png

Step 2: Access the Underlying Query

After creating the parameter in Bold BI®, switch to the code view mode to access the underlying query of the data source. Copy this query as it will be used as a base for the next data source.

screenshot2.png

Step 3: Create a New Data Source with Modified Query

Create a new data source named “Datasource2”. Use the query copied from “Datasource1” and modify it by adding a WHERE condition that filters data from the past five years based on the dashboard parameter.

SELECT
    [Sheet1].[Date] AS [Date],
    [Sheet1].[Type] AS [Type],
    [Sheet1].[Value] AS [Value]
FROM [Datasource].[Sheet1] AS [Sheet1]
WHERE
    CONCAT(DATEPART(DAY,[Sheet1].[Date]),'-',DATEPART(MONTH,[Sheet1].[Date])) = CONCAT(DATEPART(DAY, CAST(@{{:Datasource1.Parameter1}} AS Date)),'-',DATEPART(MONTH, CAST(@{{:Datasource1.Parameter1}} AS Date)))
    AND YEAR([Sheet1].[Date]) BETWEEN YEAR(GETDATE()) - 4 AND YEAR(GETDATE())

screenshot3.png

Step 4: Bind the Data Source to Your Dashboard

Save “Datasource2” with the modified query. Bind this data source to your dashboard, ensuring that the data displayed is filtered based on the parameter. Use a widget, such as a date picker, where the user can select the specific date. Drag and drop the dashboard parameter column into the assign data section of the date picker widget to control the filtering.

sshot-5.png

Step 5: Test the Filter

Test the filter by selecting a date in the date picker widget and verifying that the dashboard updates to show data from the past five years relative to the selected date.

Additional References:

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
MM
Written by Mahendran Maragatha Patchai
Updated Jun 19, 2024
Comments (0)
Please  to leave a comment
Access denied
Access denied