I have a 2D array, and I'm trying to use select to build a separate array using index 3 of each internal array (e.g., given starting array is [['An', 'Example', 'Array', 'Here'], ['But', 'It', 'Won't', 'Work']], I want ['Here', 'Work']). However, any index other than 0 will give me this error:
The evaluation of 'query' action 'where' expression '@item()[1]' failed: 'The template language expression 'item()[1]' cannot be evaluated because array index '1' is outside bounds (0, 0) of array.
I can check the length of each array just fine and index 0 is always correct so this really doesn't make any sense to me, and I'd appreciate any help. I'm also trying to avoid standard loops as they GREATLY reduce performance. Thanks!
Solved! Go to Solution.
Really I needed an array of each array within a 2D array at index X. X is variable and the size of the arrays are variable as well which is why I needed a dynamic solution. Although it's not graceful, I have a solution through trimming/filtering my arrays and creating a new 2D array with createArray(item[X],...) along with all the other inputs I require. This leaves it in a form that allows me to use the data more effectively. This wouldn't work before as mentioned since attempting to call item[X] where X != 0 caused issues, I still don't fully understand why, and that's why I came here, but I've worked around it.
I've moved on to another, more complicated case, but I won't get into that here, thanks for the help anyway.
Hi @sloanad2 ,
Try the following:
[
[
"An",
"Example",
"Array",
"Here"
],
[
"But",
"It",
"Won't",
"Work"
]
]
createArray(variables('varArray')?[0]?[3], variables('varArray')?[1]?[3])
Ellis
____________________________________
If I have answered your question, please mark the post as Solved.
If you like my response, please give it a Thumbs Up.
@ekarim2020 Unfortunately I need this solution to work dynamically so adding each one by one isn't going to work for me.
Edit: Also my method of using select should work, it does in a test environment, but for some reason it's not working in the actual flow, where the dataset is significantly larger, although I'm not sure if that's the source of the issue.
Hi @sloanad2 ,
Please provide further details for the rule you need in order to generate the third array. From your original post it seems that you need the last item from each of the nested arrays. If this is the case, you can use the following expressions:
createArray(last(first(variables('varArray'))), last(last(variables('varArray'))))
Please post extracts from your working flow, including more sample data. Are you using the same sample data to test the flows in both your Test and Production environment?
Ellis
____________________________________
If I have answered your question, please mark the post as Solved.
If you like my response, please give it a Thumbs Up.
Select will iterate through each of the inner arrays, so all you need to do is have the following:
item()[3]
This is using an array variable with any number of inner arrays. You just need to ensure you have at least 4 items in each.
If that's what you already have and it's not working, then I'd be looking at your array to see if it's malformed in some way.
Really I needed an array of each array within a 2D array at index X. X is variable and the size of the arrays are variable as well which is why I needed a dynamic solution. Although it's not graceful, I have a solution through trimming/filtering my arrays and creating a new 2D array with createArray(item[X],...) along with all the other inputs I require. This leaves it in a form that allows me to use the data more effectively. This wouldn't work before as mentioned since attempting to call item[X] where X != 0 caused issues, I still don't fully understand why, and that's why I came here, but I've worked around it.
I've moved on to another, more complicated case, but I won't get into that here, thanks for the help anyway.
User | Count |
---|---|
95 | |
46 | |
21 | |
18 | |
17 |
User | Count |
---|---|
141 | |
50 | |
43 | |
40 | |
29 |