JuanFelipe Posted November 28, 2019 Share Posted November 28, 2019 (edited) Hello friends, I come back to you for your help, I have a table which I need to add the repeated data, but only if they coincide in two columns, example: If position [X] [0] and position [X] [1] have more matches in the array, they are added to position [X] [3]. I have tried to do it in the following way, it makes the first positions, but the others do not, I know what the error is, that's why I need your help, I can't think of anything else, thanks. expandcollapse popupFunc _Limpiar($bArray) Local $aFinal[1][3] $aFinal[0][0] = $bArray[0][0] $aFinal[0][1] = $bArray[0][1] $aFinal[0][2] = $bArray[0][2] _ArrayDelete($bArray,0) ;_ArrayDisplay($bArray) ;_ArrayDisplay($aFinal) While UBound($bArray,$UBOUND_ROWS) > 0 Local $Index[0] For $i = 0 To UBound($bArray, $UBOUND_ROWS)-1 If ($aFinal[UBound($aFinal, $UBOUND_ROWS)-1][0] == $bArray[$i][0]) Then _ArrayAdd($Index,$i) EndIf Next ;_ArrayDisplay($Index) ;_ArrayDisplay($bArray) If UBound($Index, $UBOUND_ROWS)>0 Then $num = UBound($aFinal, $UBOUND_ROWS)-1 For $i=0 To UBound($Index, $UBOUND_ROWS)-1 If ($aFinal[$num][0] == $bArray[$Index[$i]][0]) And ($aFinal[$num][1] == $bArray[$Index[$i]][1]) Then $aFinal[$num][2] += $bArray[$Index[$i]][2] Else Local $sFill = $bArray[$Index[$i]][0]&"|"&$bArray[$Index[$i]][1]&"|"&$bArray[$Index[$i]][2] _ArrayAdd($aFinal, $sFill) EndIf Next For $i=0 To UBound($Index, $UBOUND_ROWS)-1 _ArrayDelete($bArray, 0) Next Else Local $sFill = $bArray[0][0]&"|"&$bArray[0][1]&"|"&$bArray[0][2] _ArrayAdd($aFinal, $sFill) _ArrayDelete($bArray, 0) EndIf ;_ArrayDisplay($bArray,"salida") ;_ArrayDisplay($aFinal,"prueba") WEnd Return $aFinal EndFunc Table example. Edited November 28, 2019 by JuanFelipe Link to comment Share on other sites More sharing options...
Developers Jos Posted November 28, 2019 Developers Share Posted November 28, 2019 Moved to the appropriate forum. Moderation Team SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Nine Posted November 28, 2019 Share Posted November 28, 2019 2 hours ago, JuanFelipe said: I have a table which I need to add the repeated data, but only if they coincide in two columns, example: If position [X] [0] and position [X] [1] have more matches in the array, they are added to position [X] [3]. Could you explain some more as I cannot figure out exactly what you want to achieve... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
jchd Posted November 28, 2019 Share Posted November 28, 2019 Your data sample looks like some inventory data. Do you mean that you have to merge (sum stock quantities) from identical {description, size} entries? That is, for instance merge entries: Codos | 4" | 6 Codos | 4" | 4 into: Codos | 4" | 10 ans so on? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
JuanFelipe Posted December 1, 2019 Author Share Posted December 1, 2019 On 11/28/2019 at 5:38 PM, jchd said: Your data sample looks like some inventory data. Do you mean that you have to merge (sum stock quantities) from identical {description, size} entries? That is, for instance merge entries: Codos | 4" | 6 Codos | 4" | 4 into: Codos | 4" | 10 ans so on? Exactly. Link to comment Share on other sites More sharing options...
jchd Posted December 1, 2019 Share Posted December 1, 2019 You can do like this: expandcollapse popup#include "..\include\ArrayMultiColSort.au3" ; description, size, quantity Local $aIn = [ _ ["BBB", "4l", 1], _ ["AAA", "8m", 10], _ ["CCC", "1m²", 37], _ ["BBB", "4l", 19], _ ["EEE", "10kg", 7], _ ["AAA", "12m", 17], _ ["BBB", "4l", 4], _ ["AAA", "8m", 11], _ ["CCC", "1m²", 3], _ ["BBB", "20l", 6], _ ["AAA", "8m", 7], _ ["DDD", '3"', 2] _ ] Local $bOut = _Limpiar($aIn) _ArrayDisplay($bOut) Func _Limpiar($b) Local $SortFmt = [[0, 0], [1, 0]] _ArrayMultiColSort($b, $SortFmt) Local $i = 0, $j = 0 $b[$j][0] = $b[$i][0] $b[$j][1] = $b[$i][1] $b[$j][2] = $b[$i][2] For $i = 1 To UBound($b) - 1 If $b[$i][0] = $b[$i - 1][0] And $b[$i][1] = $b[$i - 1][1] Then $b[$j][2] += $b[$i][2] Else $j += 1 $b[$j][0] = $b[$i][0] $b[$j][1] = $b[$i][1] $b[$j][2] = $b[$i][2] EndIf Next ReDim $b[$j + 1][UBound($b, 2)] Return $b EndFunc using this UDF by @Melba23 JuanFelipe 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
JuanFelipe Posted December 1, 2019 Author Share Posted December 1, 2019 10 hours ago, jchd said: You can do like this: expandcollapse popup#include "..\include\ArrayMultiColSort.au3" ; description, size, quantity Local $aIn = [ _ ["BBB", "4l", 1], _ ["AAA", "8m", 10], _ ["CCC", "1m²", 37], _ ["BBB", "4l", 19], _ ["EEE", "10kg", 7], _ ["AAA", "12m", 17], _ ["BBB", "4l", 4], _ ["AAA", "8m", 11], _ ["CCC", "1m²", 3], _ ["BBB", "20l", 6], _ ["AAA", "8m", 7], _ ["DDD", '3"', 2] _ ] Local $bOut = _Limpiar($aIn) _ArrayDisplay($bOut) Func _Limpiar($b) Local $SortFmt = [[0, 0], [1, 0]] _ArrayMultiColSort($b, $SortFmt) Local $i = 0, $j = 0 $b[$j][0] = $b[$i][0] $b[$j][1] = $b[$i][1] $b[$j][2] = $b[$i][2] For $i = 1 To UBound($b) - 1 If $b[$i][0] = $b[$i - 1][0] And $b[$i][1] = $b[$i - 1][1] Then $b[$j][2] += $b[$i][2] Else $j += 1 $b[$j][0] = $b[$i][0] $b[$j][1] = $b[$i][1] $b[$j][2] = $b[$i][2] EndIf Next ReDim $b[$j + 1][UBound($b, 2)] Return $b EndFunc using this UDF by @Melba23 THANK YOU, it works perfectly. Link to comment Share on other sites More sharing options...
jchd Posted December 1, 2019 Share Posted December 1, 2019 Don't quote the full post you want to reply to, keep that for the part that need quoting, if any. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
JuanFelipe Posted December 1, 2019 Author Share Posted December 1, 2019 13 minutes ago, jchd said: Don't quote the full post you want to reply to, keep that for the part that need quoting, if any. Sorry sir. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now