简体   繁体   English

Power Automate - 需要帮助根据一个字段(字符串格式的数字)对数组进行排序

[英]Power Automate - Need help sorting an array based on one field that's a number in string format

I have an array of data and all values are in string format due to some prior JSON operations in the flow.我有一个数据数组,由于流程中的一些先前的 JSON 操作,所有值都是字符串格式。 I need to sort the array based on one field which are numbers (in string format).我需要根据一个数字字段(字符串格式)对数组进行排序。 I'm using the sort function and it currently sorts the array, but it's done as a string and sorts 'alphabetically' (eg "20", "290", "3", "300", "31" instead of the desired "3", "20", "31", "290", "300")我正在使用 function 排序,它目前对数组进行排序,但它是作为一个字符串完成的,并按“字母顺序”排序(例如“20”、“290”、“3”、“300”、“31”而不是所需的“3”、“20”、“31”、“290”、“300”)

I've tried using Int() and Float() to convert the field to an integer. I'm using the functions wrapped around the mapped item in a select action int(item()?['Points_Total']) with no success.我尝试使用Int()Float()将字段转换为 integer。我在 select 操作int(item()?['Points_Total'])中使用围绕映射项目的函数但没有成功. See images.查看图像。

Both functions give the same error:这两个函数给出相同的错误:

The template language function ('int' or 'float') was invoked with a parameter that is not valid.使用无效参数调用模板语言 function(“int”或“float”)。 The value cannot be converted to the target type.该值无法转换为目标类型。

The data in the field are whole numbers, both positive and negative.该字段中的数据是整数,包括正数和负数。 I'd think that both functions could handle the values I'm working with.我认为这两个函数都可以处理我正在使用的值。

Here is how I'm trying to convert the field Points_Total:这是我尝试转换字段 Points_Total 的方法:

在此处输入图像描述

Error and View of Data Field数据字段的错误和视图

在此处输入图像描述

Any ideas from the community?来自社区的任何想法?

Thank you!谢谢!

I'd suggest you have a blank value there somewhere.我建议你在某处有一个空白值。 You'll need to check for that prior to converting to a numeric value.在转换为数值之前,您需要检查一下。 Your expression should be changed to something like this...你的表情应该改成这样……

if(isInt(item()?['Points_Total']), int(item()?['Points_Total']), 0)

... my suggestion would be to set it to zero in the cases where it's not a number however, if that skews your results, etc. then you can choose what you do. ......我的建议是在它不是数字的情况下将其设置为零,但是,如果这会扭曲你的结果等,那么你可以选择你做什么。

Also, I've used isInt given you said the numbers are whole.另外,我使用isInt给你说数字是完整的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM