Filter data for dashboard

Hi everyone,

I am having a node that generates for each day of the year some power consumption data:

["01-06-2024",9,0,"test"]
["02-06-2024",10,7,"test"]
["03-06-2024",12,0,"test"]
["04-06-2024",5,1,"test"]
["05-06-2024",4,1,"test"]
["06-06-2024",2,0,"test"]
["07-06-2024",1,0,"test"]
... until
["31-12-2024",1,0,"test"]

I display these data in a dashboard.

I would like to add a dropdown with the months selection, so that only the data of the selected month will be displayed but I am struggling on creating a function to select only the lines relevant for the selected month.

Could ou help me on that function?
Many thanks,
Thomas

Where does the data come from?

It's a bit unusual to see DD-MM-YYYY date format in input data. YYYY-MM-DD might be easier to work with.

For example this function returns 7

const datestring = "2024-07-12"
const monthnum = new Date(datestring).getMonth() + 1
msg.payload = monthnum
return msg;

Yes, I’m able to capture this from the date as well, but how to build a function able to delete (or extract) all strings that are not from the relevant month ?

The data are coming from an external Energy provider database which I store in a local file.

Your input data looks like an array of arrays.

Use a split node to create one message per day eg ["01-03-2024",9,0,"test"]
Then a function node can test the value of the month part of the date, something like this

const chosenmonth = flow.get("chosenmonth") || ""
if (msg.payload[0].split("-")[1] == chosenmonth) {
    return msg;
}

Then either pass the filtered messages on individually or use a join node to recreate the array of arrays structure.

This is working fine, many thanks Jbudd :slight_smile: