cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mahmoodhsaud
Helper IV
Helper IV

Find max value in a collection

Hi Everyone,

 

 I have a table with column Name, Group sequence and Account Sequence. I wanted to find the max value in group sequence and account sequence and set it to 0.

 

Table 1 :

mahmoodhsaud_0-1631095655945.png

 

Table 1 after finding the max value and updating it to zero

mahmoodhsaud_1-1631095705225.png

 

Thanks in Advance,

 

Regards,

Mahmood

 

5 REPLIES 5
rampprakash
Memorable Member
Memorable Member

Hi @mahmoodhsaud,

 

You can try below code

 

Set(getMaxValue,Max(TableName,Column name);

 

Use 

UpdateIf( TableName, columnname=getMaxValue, { ColumnName: 0 } )

 

 

Please Mark as answer and give Kudos if its helpful.

 

Subscribe : https://youtube.com/channel/UCnGNN3hdlKBOr6PXotskNLA

Blog : https://microsoftcrmtechie.blogspot.com

Prakash4691
Solution Specialist
Solution Specialist

@mahmoodhsaud 

 

Try below formula for onselect property of button.

 

FYI, max is not a delegable function, will not work directly with underlying datasource. That is why I have created collection to avoid delegation issue.

 

ClearCollect(Test2List, 'Test 2S');
ForAll(Test2List,
UpdateIf('Test 2S', 'Num 1' = Max(Test2List, 'Num 1'), {'Num 1':0},
'Num 2' = Max(Test2List, 'Num 2'), {'Num 2': 0}))

 

Test 2S is the entity, Num 1 and Num 2 are the columns.

 

If it answers your question, give kudo and accept it as solution.

 

 

Regards,

Prakash

Thanks @rampprakash for your valuable inputs, The above formula will work fine for the third column(Account Sequence) whereas in column 2 ( Group Sequence )we will be getting more than one max value based on the column 3

Hello @mahmoodhsaud,

 

Yes in the first variable we will get he Maximum number (Variable will return which is the Maximum number in the column- only one value 0,1,2,3 the output will be 3) 

 

Then based on output we will update the records

 

UpdateIf( TableName, columnname=getMaxValue, { ColumnName: 0 } )

 

Let me know if it's not helpful.

Please Mark as answer and give Kudos if its helpful.

 

 

 

Subscribe : https://youtube.com/channel/UCnGNN3hdlKBOr6PXotskNLA

 

Blog : https://microsoftcrmtechie.blogspot.com

Hi @rampprakash ,

 

In the second column, we need to find the max based on third column. In the below table we will be getting two max value in Group Sequence.

The max value in account sequence 1 is 3 and max value in account sequence 2 is 4. Both should be set to 0.

 

mahmoodhsaud_1-1631169167805.png

 

 

 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (3,435)