How to count the filtered data of the database and display it on the page?

I would like to create a dashboard and display the count of filtered data as a text field.

I created a database and added the field named as status. This field has different values like: In Progress, Completed, Pending.

I would like to filter only Completed value and count it.

I tried to code it but for some reason I’m getting parsing error: Unexpected token if.

Can someone explain to me what this ‘‘parsing error’’ means and how to fix the code?

Data:
Dataset name: Dataset1
Database field key: status
Text field ID: textCount

import wixData from 'wix-data';

$w.onReady(() => {
    wixData.query("dataset1").onReady(() => {
        count();
 
 function count() {
 let total = $w("#dataset1").setFilter(wixData.filter().contains("status", "Completed").getTotalCount()
 
 if (total > 0) {  // Parsing error
 
            $w('#textCount').text = `${total} result has found.`;
        } else {
            $w('#textCount').text = "No result found!";

            }
        }   
    })
})
1 Like