Category / Section
How to display MySQL records Month wise for last 'N' months in Bold BI
Published:
Follow the below steps to display records month wise for last 'N' months for MySQL data source.
Steps to display records month wise:
For the corresponding date field, create a list-based dashboard parameter under the "Custom Query" option.
(SELECT MAX(`<column-name>`) AS `<name>` FROM `<table-name>` AS `<name>` LIMIT 1)
Sample query: (SELECT MAX(`100000 Records`.`42f47c50-c051-4565-8573-a49848817b7f`) AS `maxdate` FROM `datasource_8be8c0a1-923d-4992-aaeb-212c433e323f`.`100000 records` AS `100000 Records` LIMIT 1)- Convert the parameter to a datetime field by creating the following expression:
CAST(@{{:Parameter1}} AS DATETIME)
- Create expressions to fetch data based on the latest month and previous months.Latest month:
IF (YEAR([Date]) = YEAR([Maxdate]) AND MONTH([Date]) = MONTH([Maxdate]), [Integer], 0)Previous month: IF (YEAR([Date]) = YEAR([Maxdate]) AND MONTH([Date]) = MONTH([Maxdate]) - 1, [Integer], 0) - Use the expressions to display the data in your dashboard.
Note: The date format should be `yyyy/MM/dd`.
Note: The year also needs to be compared to get the correct data.