Summing extra column(s) with script

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Online
Schuller
Posts: 52
Joined: 02 May 2023 21:08

Summing extra column(s) with script

Post by Schuller »

Hi again,

I have another question:

I have some column layouts with a few extra columns configured to a number type, then in those columns there are dollar values entered. I'm using these column layouts to assist me with things such as "off the books" asset/inventory tracking, articles for sale, etc... So my question: is there anyway to easily autosum those particular extra column values and then have them displayed "on the fly" in area like the status bar? or alternatively, in a popup after clicking, let's say, a "compute" custom user button once I select all items or if I select few just a few items.

Thanks
Last edited by Schuller on 22 Sep 2023 21:33, edited 5 times in total.

highend
Posts: 13033
Joined: 06 Feb 2011 00:33

Re: Autosum of an Extra Column when it is configured as "Type" Number

Post by highend »

Why is this a bug report?

And to answer the question: Sure, scripting can do that (e.g. invoked via button)...
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

Online
Schuller
Posts: 52
Joined: 02 May 2023 21:08

Re: Autosum of an Extra Column when it is configured as "Type" Number

Post by Schuller »

Thanks for the response highend.
I only noticed that this was posted in Bug Reports now that you've pointed it out. I'm still learning to navigate my way around the forum and I'll admit, as a newbie, it took me a while to figure just where to post a topic.
Anyway, if there is a way to remove it from bug reports then please advise.

highend
Posts: 13033
Joined: 06 Feb 2011 00:33

Re: Autosum of an Extra Column when it is configured as "Type" Number

Post by highend »

*Moved*
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

Online
Schuller
Posts: 52
Joined: 02 May 2023 21:08

Re: Autosum of an Extra Column when it is configured as "Type" Number

Post by Schuller »

Okay, thanks for moving it and I've noted my error for the next time I create a topic.

I would definitely be interested in creating that sort of button with a script as there would be many instances in my working environment where a calculation button like that would prove beneficial, but unfortunately I don't have any scripting experience so I'm not sure where to begin. Are there any templates that you could direct me to that are either similar or the same that I could copy, paste, modify, etc..? I've done a whole lot of reading in the forums already and had not noticed anything like that yet.

highend
Posts: 13033
Joined: 06 Feb 2011 00:33

Re: Autosum of an Extra Column when it is configured as "Type" Number

Post by highend »

It would need to be tailored to your case anyway (.e.g depending on what column for storage data is used)

Type = Number only allows numbers without fraction(s). Does that make sense at all?

Show a screenshot (of items with such data)...
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

Online
Schuller
Posts: 52
Joined: 02 May 2023 21:08

Re: Autosum of an Extra Column when it is configured as "Type" Number

Post by Schuller »

Yes, I understand that "Type = Number" is rounded and fractions don't work. Is there a way to have that modified too, to include fractions? ie: 27.68? and perhaps even include a symbol such as the $?
In some cases where fractions were needed I've selected Type = Text but imagine that would create issue for autosum.

highend
Posts: 13033
Joined: 06 Feb 2011 00:33

Re: Autosum of an Extra Column when it is configured as "Type" Number

Post by highend »

Choose text. Reformatting into something "usable" should be part of a script
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

Online
Schuller
Posts: 52
Joined: 02 May 2023 21:08

Re: Autosum of an Extra Column when it is configured as "Type" Number

Post by Schuller »

Here is an attachment of just one example I'd like to use a custom button with a script that can sum the dollar value of a column. In this case it would be the price and sold column where the screenshot only shows 29 items but its actually over 100 items. I have several other types of columns layouts with similar types of calculation where it is all just summing so hopefully this same button would work on those columns, or the same script could be slightly modified to a second button if needed.

Thanks
Attachments
2023.09.19 screenshot.png
2023.09.19 screenshot.png (132.82 KiB) Viewed 477 times
Last edited by Schuller on 21 Sep 2023 21:20, edited 1 time in total.

highend
Posts: 13033
Joined: 06 Feb 2011 00:33

Re: Autosum of an Extra Column when it is configured as "Type" Number

Post by highend »

This should work for all column setups...

Code: Select all

    $columnHeaders = setcolumns(, 64); // ","-separated
    // E.g.: Name,Price $,Sold $,Modified,Created

    $visibleColumns = regexmatches(columnlayout(, "get"), "\+[^.]+");
    // E.g.: +Name|+Extra 1|+Extra 2|+Modified|+Created

    // Make sure both counts are equal, otherwise a "," is used as a caption in a column
    $cntColumnHeaders  = gettoken($columnHeaders, "count", ",");
    $cntVisibleColumns = gettoken($visibleColumns, "count", "|");
    end ($cntColumnHeaders != $cntVisibleColumns), "A ',' is not allowed in column header(s), aborted!";

    $chosenColumns = inputselect("Select column(s) to sum up", $columnHeaders, ",", 2+8192+16384, , 300, 400);
    end !($chosenColumns), "No column(s) chosen, aborted!";

    // Create report
    $selected = <get SelectedItemsNames>;
    $itemList = ($selected) ? 1 : 0;
    $report   = report("|", $itemList);
    // E.g.: 1|deep cool fans|$30,00||21.09.2023 14:15:03|21.09.2023 14:15:03
    //       2|dewalt - drill 12v|$25,00|$20,00|21.09.2023 14:15:09|21.09.2023 14:15:09
    //       3|dewalt - drill 20v|$100,00|$90,00|21.09.2023 14:15:21|21.09.2023 14:15:21
    //       4|tripod||$10,50|21.09.2023 14:15:36|21.09.2023 14:15:36

    // Remove line numbers if visible
    $report = get("#406") ? regexreplace($report, "^\d+\|") : $report;

    // Get the digits of the columns to autosum
    $chosenDigitColumns = "";
    foreach($column, $chosenColumns, ",", "e") {
        $chosenDigitColumns .= gettokenindex($column, $columnHeaders, ",", "") . "|";
    }
    $chosenDigitColumns = trim($chosenDigitColumns, "|");

    // Sum up
    $log = "";
    foreach($num, $chosenDigitColumns, "|", "e") {
        // Create and initialize count variables
        $var  = '$col_' . $num;
        *$var = 0;

        // Get the real column name
        $realColumn = gettoken($columnHeaders, $num, ",", "t");

        status "Calculating " . quote($realColumn) . " ...", , "progress";
        foreach($line, $report, <crlf>, "e") {
            $value  = gettoken($line, $num, "|", "t");
            $value  = regexmatches($value, "[0-9,.]+");
            *$var  += $value;
        }
        // Create log
        $log .= "Sum [" . $realColumn . "]: " . *$var . <crlf>;
    }
    end !($log), "No log created?";

    text $log;
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

Online
Schuller
Posts: 52
Joined: 02 May 2023 21:08

Re: Autosum of an Extra Column when it is configured as "Type" Number

Post by Schuller »

Okay, going to try it.
Actually quite excited to try my first script. Will get back again after I've tried it.
Thanks!

Online
Schuller
Posts: 52
Joined: 02 May 2023 21:08

Re: Autosum of an Extra Column when it is configured as "Type" Number

Post by Schuller »

This script works perfect highend, Thank you! :D
I've tried my new custom user button now on a few of my column layouts and they all work great.
On another note, and I'm hoping I don't have to create a new topic for this, would you happen to know if there is way I can increase the amount of extra columns from 16 to say 20?

highend
Posts: 13033
Joined: 06 Feb 2011 00:33

Re: Summing extra column with script

Post by highend »

Thx for the donation :tup:

The number of extra columns is limited, no way to have more than 16 atm.

But you could always store more delimited stuff in the tags- or even the extra columns by adding a separator between your data items (which can not be "|" or <crlf>) and create a script that get's the correct data from such a column (and use one of the 64 extra columns for that script)...
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

Online
Schuller
Posts: 52
Joined: 02 May 2023 21:08

Re: Summing extra column with script

Post by Schuller »

Okay, I think I'll move forward with baby steps at this time with scripting and just work with what I have at the moment.
I'll get back if that possible feature becomes really pressing.

Thanks again.

Online
Schuller
Posts: 52
Joined: 02 May 2023 21:08

Re: Summing extra column(s) with script

Post by Schuller »

I have another question highend that I'm hoping you can assist me with in finding a work-around or tweak and this relates to the first popup box that is displayed after clicking the custom summing button that I created using your script.

Recently I upgraded my dual monitor setup from 27", 1080p to 28", 4K, and now the first popup box that is displayed after I click the custom sum button has to be resized each time with this 3840x2160 resolution. I've added an attachment here to illustrate.
Screenshot of popup with new 4K monitor.jpg
Screenshot of popup with new 4K monitor.jpg (25.05 KiB) Viewed 154 times
When I override the high dpi scaling in XY's properties then the popup box size is fine and is just as it was with my old 1080p monitors.
overide high dpi scaling.jpg
overide high dpi scaling.jpg (261.82 KiB) Viewed 154 times
Screenshot of popup after overiding high dpi scaling (just like older 1080p monitors).jpg
Screenshot of popup after overiding high dpi scaling (just like older 1080p monitors).jpg (36.78 KiB) Viewed 154 times
I prefer the look of things though with the new 3840x2160 resolution and almost everything else appears fine(after some adjustments) so my question is; can this popup box size be tweaked without overriding the high dpi? If so, can you please assist?

Thanks

Post Reply