Skip to main content

Notifications

Power Automate - Building Flows
Answered

NESTED IF STATEMENTS IN A FUNCTION

(0) ShareShare
ReportReport
Posted on by 33
Hi, I'm trying to create a flow that uses AI to extract a code from a document then adds the details to a sharepoint list. The code is made of a Letter and a number the Letter sets it as a Category and the number sets it to a Area.

I tried to do this with nested if statements but it just gives me an error. is there a better more efficient way to do this? There are a lot of code variations so my nested if looked like this and it was even larger for the Area being recognised off a number. I have 49 numbers in the code sequence. I also worry that if i was using the below for the numbers then it would mix up when trying to recognise 1 for 10,11 etc.
 
Any better ways to do this would be really appreciated.

Thanks
James

if(contains(variables('Budget_Code'), 'A'), 'COLUMNS',
if(contains(variables('Budget_Code'), 'B'), 'STRIP FOOTINGS',
if(contains(variables('Budget_Code'), 'C'), 'LIFT PAD',
if(contains(variables('Budget_Code'), 'D'), 'FOOTINGS',
if(contains(variables('Budget_Code'), 'E'), 'NON PT SLABS',
if(contains(variables('Budget_Code'), 'F'), 'SHEAR WALL',
if(contains(variables('Budget_Code'), 'G'), 'CORE WALLS',
if(contains(variables('Budget_Code'), 'H'), 'BUTTRESS WALLS',
if(contains(variables('Budget_Code'), 'I'), 'STAIRS',
if(contains(variables('Budget_Code'), 'J'), 'UPSTANDS',
if(contains(variables('Budget_Code'), 'K'), 'HOBS',
if(contains(variables('Budget_Code'), 'L'), 'MISCELLANEOUS',
if(contains(variables('Budget_Code'), 'M'), 'SUSPENDED PT SLAB WITH BEAMS',
if(contains(variables('Budget_Code'), 'N'), 'PT DIAPHRAGM',
if(contains(variables('Budget_Code'), 'O'), 'NON PT SLABS (COMPOSITE/BONDEC)',
if(contains(variables('Budget_Code'), 'P'), 'SAFETY MESH (SL82)',
'MISC')))))))))))))))))
  • jpdamd Profile Picture
    jpdamd 33 on at
    NESTED IF STATEMENTS IN A FUNCTION
    Thanks guys, that has worked perfectly to pull through the Category. Struggling a bit to get it to work with my Level though. Below is the array I've created. my budget codes are all 2 to 3 digits in the below format

    A1
    C10
    D15
    This is how they appear within the BUDGET CODE variable. So the first Category array is working and recognising the letter and assigning the Category. How can i do the same but get it to look at the number and then return from my array below? 

    Thanks so much 

    [
    {
    "Number": 1,
    "Level": "RAFT SLAB"
    },
    {
    "Number": 2,
    "Level": "B4"
    },
    {
    "Number": 3,
    "Level": "B3"
    },
    {
    "Number": 4,
    "Level": "B2"
    },
    {
    "Number": 5,
    "Level": "B1"
    },
    {
    "Number": 6,
    "Level": "GF"
    },
    {
    "Number": 7,
    "Level": "UGF"
    },
    {
    "Number": 8,
    "Level": "L1"
    },
    {
    "Number": 9,
    "Level": "L2"
    },
    {
    "Number": 10,
    "Level": "L3"
    },
    {
    "Number": 11,
    "Level": "L4"
    },
    {
    "Number": 12,
    "Level": "L5"
    },
    {
    "Number": 13,
    "Level": "L6"
    },
    {
    "Number": 14,
    "Level": "L6M"
    },
    {
    "Number": 15,
    "Level": "L7"
    },
    {
    "Number": 16,
    "Level": "L8"
    },
    {
    "Number": 17,
    "Level": "L9"
    },
    {
    "Number": 18,
    "Level": "L10"
    },
    {
    "Number": 19,
    "Level": "L11"
    },
    {
    "Number": 20,
    "Level": "L12"
    },
    {
    "Number": 21,
    "Level": "L13"
    },
    {
    "Number": 22,
    "Level": "L14"
    },
    {
    "Number": 23,
    "Level": "L15"
    },
    {
    "Number": 24,
    "Level": "L16"
    },
    {
    "Number": 25,
    "Level": "L17"
    },
    {
    "Number": 26,
    "Level": "L18"
    },
    {
    "Number": 27,
    "Level": "L19"
    },
    {
    "Number": 28,
    "Level": "L20"
    },
    {
    "Number": 29,
    "Level": "L21"
    },
    {
    "Number": 30,
    "Level": "L22"
    },
    {
    "Number": 31,
    "Level": "L23"
    },
    {
    "Number": 32,
    "Level": "L24"
    },
    {
    "Number": 33,
    "Level": "L25"
    },
    {
    "Number": 34,
    "Level": "L26"
    },
    {
    "Number": 35,
    "Level": "L27"
    },
    {
    "Number": 36,
    "Level": "L28"
    },
    {
    "Number": 37,
    "Level": "L29"
    },
    {
    "Number": 38,
    "Level": "L30"
    },
    {
    "Number": 39,
    "Level": "L32"
    },
    {
    "Number": 40,
    "Level": "L33"
    },
    {
    "Number": 41,
    "Level": "L34"
    },
    {
    "Number": 42,
    "Level": "L35"
    },
    {
    "Number": 43,
    "Level": "L36"
    },
    {
    "Number": 44,
    "Level": "L37"
    },
    {
    "Number": 45,
    "Level": "L38"
    },
    {
    "Number": 46,
    "Level": "L39"
    },
    {
    "Number": 47,
    "Level": "ROOF"
    }
    ]
  • Verified answer
    Expiscornovus Profile Picture
    Expiscornovus 31,144 on at
    NESTED IF STATEMENTS IN A FUNCTION
    Like mentioned by EKarim it would be great to get some sample data to determine a pattern.
     
    In the past I have also used a mapping array for this. So, this might work for you as well. You can create a array with the letter/category mapping and use a filter array action to find the matching item based on the budget_code variable value.
     
    Below is an example of that approach.
     
    1. The filter in the Filter Array
    @contains(variables('Budget_Code'), item()['Letter'])
     
     
    2. The expression to return the category of the matching letter
     
    first(body('Filter_Array'))['category']
     
    A test result.
     
  • jpdamd Profile Picture
    jpdamd 33 on at
    NESTED IF STATEMENTS IN A FUNCTION
    Thanks Ellis,

    Yep my Budget code ranges from A1 to P49. See below. in the screen shot you can see that the number 1 in the code reflects Level or Area 'RAFT SLAB' while A is for the Category 'COLUMNS'
    The number 2 in the code would be for area B4, etc

  • Ellis Karim Profile Picture
    Ellis Karim 10,572 on at
    NESTED IF STATEMENTS IN A FUNCTION
    Can you provide some sample data for the budget code, so we can determine the patter for the category and area
     
    This will help determine a possible solution.
     
    Ellis
     

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,666

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,996

Leaderboard