How can you keep your app fully functional even when your users don’t have Wifi? If your users are working on a handheld device, you can conveniently save data locally. Here’s an example of how you can easily do this

Also checkout my later post on how to save multiple variables locally and reload them when the App restarts: Power Apps SaveData: Cool Cookies!

Local Data Storage

The PowerApps SaveData and LoadData formulas make it simple to store data in the Sandbox area of a handheld device.  The Sandbox is designed to segregate apps from each other for security reasons and Power Apps is an app like any other, so it has access to the Sandbox too.  You can store quite a bit of data in this way – the only limitation is the devices spare capacity. There are no security concerns if the handheld is lost or stolen as devices usually encrypt locally held data as standard.  It’s simple to code, and as you would expect it works faster that a cloud based data source

Here’s how I used local data storage for a volume on/off toggle for an off-line Power Apps game

Retain user preferences without WiFi

Step 1

Create a simple toggle imput to control whether the game sound is on or off.  If the player changes the toggle input the first record in a single column collection is updated via the OnChange property to control whether the sound is on or off.  The new boolean preference setting stored in the collection is then immediately written to local storage.  SaveData and LoadData only work with collections not variables.  If your data is in a variable then add it to a collection before saving locally

All the audio controls require the first (and only) record in the SoundPref column to be true before playing.  If the value is false, the audio doesn’t play

Step 2

Whenever the player restarts the app on the same device, their sound on/off preference is loaded from the locally stored data back into the SoundSettings collection

The optional third parameter in the LoadData formula defines what should be done if the local file doesn’t exist. False is the default setting for this parameter which returns an error; true suppresses the error message and simply returns an empty value.  The first time the app is used the file doesn’t yet exist, therefore we want to set the third parameter to true and have an empty value returned

The second section of code checks via the IsBlank function whether a value has been returned.  If not, it changes the value to true as we want the default to be ‘sound on’ for all first time users

Step 3

The collection both controls whether sound is played and is also applied to the Default property for the toggle input.  The setting can then be changed by the player if required

That’s it! The users preferences have been loaded, applied to the toggle input and ready to drive the sound option!

Upsides and downsides of local storage

Never lose data!  A key benefit of local storage is that you can allow your users to save data even when out of range of WiFi or cellular data networks

Continuity of operation is another big advantage.  Your users can continue working effectively whatever the circumstances and not need to find a network to complete one transaction before starting another

As you’d guess, the speed to save data is also noticably quicker when run side by side with storing data in the cloud, though this is unlikely to make a huge difference to everyday Power Apps users

And the downsides?   The obvious drawback is that any data saved locally is subject to potential loss.  Also you are saving data specific to that device, not the user.  If the user moves to another device the locally stored data will not be available to them

Also, local storage only works on handheld devices (ie Android and iOS).  If you are running your app in a browser local storage isn’t an option and the orange warning triangles will flag this to you when you are building your app.  For this reason you can only fully test on a published app running on a handheld too

Local storage fulfills an important role, particularly when your app is used by roaming users who are likely to be working in “Not Spots” away from the Internet

Further Reading & References

2 thoughts on “Local Data Storage”

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top