Ubidots Developer Guides
Help CenterAPI ReferenceData APICommunity
  • Welcome to our Dev Guides
  • ⚡️ Getting Started
    • What is Ubidots?
    • Devices, Variables, and Dots
    • Technical FAQs
    • Business FAQs
  • 🧩Integration Guides
    • Industrial IoT
      • Advantech
      • Amplified Engineering
      • AWS
      • Azimut
      • Balena
      • Bivocom
      • CESVA
      • Controllino
      • Digital Communications Technologies (DCT)
      • Everactive
      • Golioth
      • Kepware
      • Kunbus
      • Monnit
      • MultiTech
      • NCD.io
      • Node-RED
      • Omicron IoT
      • Red Lion
      • Robustel
      • Senquip
      • Sielco
      • Siemens
      • Strega
      • vNode
      • WAGO
      • Weintek
      • YuDash
    • Cellular
      • Blues Wireless
      • Digi International
      • Hologram
      • Monogoto
      • Particle
      • Quectel
      • Soracom
    • LoRaWAN
      • AonChip
      • Chirpstack
      • Decentlab
      • Helium
      • ioThings
      • LORIOT
      • Milesight
      • MOKOSmart
      • RAKwireless
      • Sagemcom
      • Seeed Studio
      • Senet
      • The Things Industries
        • The Things Stack
        • The Things Network
    • Sigfox
      • Digital Matter
      • McThings
      • Sigfox
      • Suntech
      • Thinxtra
      • UnaBiz
    • Satellite
      • Swarm
    • Dev Kits
      • Adafruit
      • Advantech
      • AloriumTech
      • Arduino
      • Blues Wireless
      • DFRobot
      • Dragino
      • Electric Imp
      • Espressif Systems
      • McThings
      • Microchip Technology
      • Onion
      • Particle
      • Pycom
      • RAKwireless
      • Raspberry Pi
      • Seeed Studio
      • Sodaq
      • STMicroelectronics
      • Texas Instruments
      • Thinxtra
      • Verse Technology
    • Weather
      • Weather Plugins
      • Ambient Weather
    • Tools
      • Gambit Communications
      • PubNub
  • 📊Dashboards & Widgets
    • HTML Canvas
      • 3rd party packages
      • Preload Dashboard data
      • Built-in library
        • Properties
        • Methods
        • Listening events
        • API
      • Examples
        • Basics
        • Create an LCD screen with the HTML Canvas
        • Interacting with dashboard data
        • Change header's custom style
        • Adding real time using Socket.IO
        • Delete Variable data from a Device
        • Delete Variable data from Groups or Types of Devices
        • Navigation through Dashboard
        • Using a React library
      • Code editor
        • HTML Tab
        • CSS Tab
        • JavaScript Tab
    • Custom UI
      • Paragraph
      • Input combo
        • Text
        • Numeric
        • Numeric with buttons
        • Date
        • Time
        • Toggle
        • Dropdown
        • Multiple selection dropdown
      • Button
    • Custom Style
      • Dashboards
      • Widgets
    • Line chart
    • Pages
      • Getting started
      • Development
      • API
        • Page creation
        • Publish
  • 🤖UbiFunctions
    • Getting Started
      • Creating an UbiFunction
      • Coding an UbiFunction
      • Testing an UbiFunction
      • Authentication
      • Execution Time
      • Logs
    • Runtimes
      • Python
      • NodeJS
      • Custom Runtimes
    • Invocation
      • Time-based Trigger
      • HTTPS
      • MQTT Publish
      • Ubidots Event
    • Advanced
      • Account Token
      • Execution time
      • Raw Functions
      • CORS Policy
      • Async Execution
      • DaaS (Decoder as a Service)
      • Developing and Managing UbiFunctions with Ubidots CLI
    • Examples
    • Specs and Limits
    • Storage
      • File Storage API
      • Mutiple files
  • 🧩Plugins
    • What is a plugin?
    • Public vs. Private
    • Public plugins
      • Cron
      • Webhook
    • Private Plugins
      • Cron
      • Webhook
      • Widget
      • Device
    • Plugins development
      • Getting started
      • Cron
      • Webhook
      • Widget
      • Device
      • view.xml
      • view_widget.xml
    • Plugins deployment
      • Cron and Webhook
      • Widget
      • Device
    • Using the plugins
      • Cron and Webhook
      • Widget
      • Device
  • 📈SYNTHETIC VARIABLES
    • Getting started
      • Creating synthetic variables
      • Synthetic Variables' editor
    • Expressions
      • Mathematical
      • Date range
      • Rolling
      • Special functions
    • Specs and limits
    • Examples
      • Mathematical
      • Date range
      • Rolling
      • Special functions
  • ⌨️Developer tools
    • Javascript SDK
      • Overview
      • Getting started
      • Ubidots class
        • Get methods
        • Filter methods
        • Ubidots objects
          • Entity object
          • Paginator
      • Examples
    • CLI
      • Overview
      • Installing
      • Usage
      • SDK for UbiFunctions
  • 🏗️Apps
    • App builder
      • Custom sidebar
Powered by GitBook
On this page
  • _

Was this helpful?

Export as PDF
  1. SYNTHETIC VARIABLES
  2. Examples

Special functions

fillfillfill_missing()missing()missing()

Syntax
Example

fill_missing (expression, <first_fill>, <last_fill>, <fill_value>)

To better understand this function, let's suppose you have a set of variables that you want to sum up together.

The variables A, B, C, and D don't have data in all of the timestamps (as shown in the table below), so the fill missing() function is used to fill in the gaps and do the calculation. The following examples are based on this table:

Date
A
B
C
D

07/12/2020 00:00:04

5

-

4

5

07/12/2020 00:00:03

3

2

3

4

07/12/2020 00:00:02

-

4

-

2

07/12/2020 00:00:01

4

3

5

-

fillfillfill_missing(A+B+C+D)missing(A + B + C + D)missing(A+B+C+D)

By default, the fill_missing() expression makes the first_fill parameter as "ffill", meaning that the function will fill the gaps forward, starting at a point where it has enough data to fill the gaps for all the involved time series. The result would be as follows:

Date
A
B
C
D
Output

07/12/2020 00:00:04

5

2

4

5

16

07/12/2020 00:00:03

3

2

3

4

12

07/12/2020 00:00:02

4

4

5

2

15

07/12/2020 00:00:01

4

3

5

-

-

fillfillfill_missing(A+B+C+D,firstmissing(A + B + C + D, firstmissing(A+B+C+D,first_fill="bfill")fill="bfill")fill="bfill")

On the other hand, it's also possible to make the first_fill a "bfill" . The gaps would be filled in the following manner:

Date
A
B
C
D
Output

07/12/2020 00:00:04

5

-

4

5

-

07/12/2020 00:00:03

3

2

3

4

12

07/12/2020 00:00:02

3

4

3

2

12

07/12/2020 00:00:01

4

3

5

2

14

fillfillfill_missing(A+B+C+D,firstmissing(A + B + C + D, firstmissing(A+B+C+D,first_fill="ffill",lastfill="ffill",lastfill="ffill",last_fill="bfill")fill="bfill")fill="bfill")

Let's suppose you need to fill all the gaps of the variables, in that case you'd need to set both first_fill and last_fill in the expression, rendering the following:

Date
A
B
C
D
Output

07/12/2020 00:00:04

5

2

4

5

16

07/12/2020 00:00:03

3

2

3

4

12

07/12/2020 00:00:02

4

4

5

2

15

07/12/2020 00:00:01

4

3

5

2

14

fillfillfill_missing(A+B+C+D,fillmissing(A + B + C + D, fillmissing(A+B+C+D,fill_value=0)value=0)value=0)

Additionally, you can fill the gaps with a value. For this case, the function sets a "0" in all the gaps the variables have.

Date
A
B
C
D
Output

07/12/2020 00:00:04

5

0

4

5

14

07/12/2020 00:00:03

3

2

3

4

12

07/12/2020 00:00:02

0

4

0

2

6

07/12/2020 00:00:01

4

3

5

0

12

cumsum()cumsum()cumsum()

Syntax
Example
Output

6

where()where()where()

Syntax
Example
Output

where(condition, operation if true, operation if false)

Step Function:

Assuming a variable

Interval Function:

Assuming a variable

diff()diff()diff()

Syntax
Example
Output

diff(<variable>,<steps>)

shift()shift()shift()

Sintax
Example
Output

shift(<variable>,<step> )

This allows you to retrieve the previous value of the variable by shifting the series to the left.

Shifts the series to the right

PreviousRollingNextJavascript SDK

Last updated 1 month ago

Was this helpful?

_

Assuming a variable

[3, 1]

Assuming a variable

Assuming a variable

📈
fillfillfill
missing(A+B)missing(A+B)missing(A+B)
cumsum(x)cumsum(x)cumsum(x)
cumsum([0,1,2,3])cumsum([0, 1, 2, 3])cumsum([0,1,2,3])
x=[−1,2,1] x = [-1, 2, 1]x=[−1,2,1]
where(x>=0,1,0)where(x >=0, 1, 0)where(x>=0,1,0)
[0,1,1][0, 1, 1][0,1,1]
x=[−1,2,1] x = [-1, 2, 1]x=[−1,2,1]
where(x<0,0,where(x<1),1,2)where(x<0, 0, where(x<1), 1, 2)where(x<0,0,where(x<1),1,2)
[0,2,2][0, 2, 2][0,2,2]
x=[14,15,17,16]x = [14, 15, 17, 16]x=[14,15,17,16]
diff(x),2)diff(x), 2)diff(x),2)
[3,1][3, 1][3,1]
x=[−2,−1,0,1,2]x = [-2, -1, 0, 1, 2]x=[−2,−1,0,1,2]
shift(x,−1)shift(x, -1)shift(x,−1)
[−1,0,1,2][-1, 0, 1, 2][−1,0,1,2]
x=[−2,−1,0,1,2]x = [-2, -1, 0, 1, 2]x=[−2,−1,0,1,2]
shift(x,2)shift(x, 2)shift(x,2)
[x,x,−2,−1,0][x, x, -2, -1, 0][x,x,−2,−1,0]