Skip to main content

Notifications

Power Automate - Building Flows
Suggested answer

Convert a number to a variable based on a range

Posted on by 18
My flow gets data and one piece that is needed comes in a number format which we need to convert to group to make it readable to the end user. The data can come in as an integer 1-360 and then that needs to be converted to a group. Example
 
1-15 = Group A
16-30 = Group B
and so on. 
 
I do not want to have a switch with 300+ options.
  • Tiago Gouveia Profile Picture
    Tiago Gouveia 2 on at
    Convert a number to a variable based on a range
    The Method 2 from @Mark response will  be excellent for the scenario you described.
    In order to make the solution a bit more dynamic and not use the lists from Method 1, I would suggest placing the array described in Method 2 into an environment variable. 
    You can put the Json Value
    [
        {
            "name": "Group A",
            "min": 1,
            "max": 15
        },
        {
            "name": "Group B",
            "min": 16,
            "max": 30
        }
    ]
    in a Environment Variable and in future dont need to update your flow. In you need more Groups ranges, only need to update the Environment Variable.
  • Suggested answer
    Mark Nanneman Profile Picture
    Mark Nanneman 329 on at
    Convert a number to a variable based on a range
    There are a few ways to handle this.  First thing I'd ask is if your "Groups" exist in any database?  For example is there a SharePoint list for "Group A", "Group B" etc?  Is there a dataverse table?


    Method 1: Filter a List in SharePoint or Dataverse

    I'd recommend creating a data source you can use in SharePoint or Dataverse or even an excel file.
     
    Easiest method migth be to just use a sharepoint list.

    - Create a "Groups" list with all your groups and add a max number and a min number column.
    - In power automate just query the SharePoint list and filter if your number is >= the min number field and <= the max number field.  In the Odata filter it'd look something like "minNumberField <= @{<your number value>} and maxNumberField >= @{<your number value>}"

    -This will output the record with the "Group" name you want.

    you could use excel to create the number ranges by selecting and dragging down--as along as you select more than two rows it'll do the math for you.



    (P.S.) you could even skip the "Min" column and just use max as long as you sort your Groups by the Max number ascending.

    Then you filter on all rows that have a Max greater than or equal to your flow's current number, and then use the first record returned.

    Method 2: Filter an array built into your flow

    You could build a simple array in your flow using a "Compose" action.

    You'de write something like this in your compose:

    [
    {"name": "Group A",
    "min": 1,
    "max":15},
    {"name": "Group B",
    "min": 16,
    "max":30},
    ...
    ]

    Then you can use a filter action on that compose action.

    Hope that helps/makes sense.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,487

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,014

Leaderboard