Latest Posts

PowerApps Check if table or collection is empty and has no records


The IsEmpty function in Power Apps is used to determine whether a table or collection is empty, meaning it contains no records. This function is particularly useful for validating data, checking if results are returned from a query, or ensuring that certain actions are only taken when there is data to process.

PowerApps – IsEmpty() function Syntax

IsEmpty(Table)

  • Table: The table or collection to check for emptiness.

Notes:

  1. Empty Collections: Ensure that collections are properly initialized and populated to avoid unexpected results when using IsEmpty.
  2. Performance: Use IsEmpty to avoid unnecessary processing or queries when no data is available, improving app performance.
  3. Error Handling: Provide meaningful messages or alternative actions when expected data is not available.

PowerApps - Check if a Collection is Empty

Suppose you have a collection named Products and you want to check if it is empty.

  1. Create the Collection:

ClearCollect(Products,

    Table(

        {ProductID: 1, ProductName: "Laptop"},

        {ProductID: 2, ProductName: "Tablet"},

        {ProductID: 3, ProductName: "Monitor"}

    )

);

  1. Add a Button to Clear the Collection:
    • Insert a Button control named ClearButton.
    • Set the Text property of the Button to "Clear Products".
    • Set the OnSelect property of the Button to:

Clear(Products)

  1. Add a Label to Display Whether the Collection is Empty:
    • Insert a Label control.
    • Set the Text property of the Label to:

If(IsEmpty(Products), "The Products collection is empty", "The Products collection is not empty")

When the button is clicked, it clears the Products collection, and the label will display "The Products collection is empty".

PowerApps – Use IsEmpty with Filtered Result

Suppose you want to check if any products in the Products collection have a price less than $500.

  1. Create the Collection with Prices:

ClearCollect(Products,

    Table(

        {ProductID: 1, ProductName: "Laptop", Price: 1000},

        {ProductID: 2, ProductName: "Tablet", Price: 500},

        {ProductID: 3, ProductName: "Monitor", Price: 300}

    )

);

  1. Add a Label to Display Whether Any Products are Under $500:
    • Insert a Label control.
    • Set the Text property of the Label to:

If(IsEmpty(Filter(Products, Price < 500)), "No products under $500", "There are products under $500")

This will display "There are products under $500" because the Products collection contains a product with a price less than $500.

PowerApps - Conditional Behavior Based on Empty Collections

Suppose you want to enable a button only if a collection is not empty.

  1. Create the Collection:

ClearCollect(Items,

    Table(

        {ItemID: 1, ItemName: "Item1"},

        {ItemID: 2, ItemName: "Item2"}

    )

);

  1. Add a Button to Perform an Action:
    • Insert a Button control named ActionButton.
    • Set the Text property of the Button to "Perform Action".
    • Set the DisplayMode property of the Button to:

If(IsEmpty(Items), DisplayMode.Disabled, DisplayMode.Edit)

This will disable the button if the Items collection is empty and enable it otherwise.


We value your Feedback:

Page URL:

Name:

Email:


Suggestion:

© 2024 Code SharePoint