In 2017 and above you can use %Parallel mentioned here:  https://docs.intersystems.com/csp/docbook/DocBook.UI.Page.cls?KEY=GSQLOPT_optquery#GSQLOPT_optquery_parallel

Off the top of my mind I'm not positive how to incorporate into your query, but I have achieved enormous performance improvements using %Parallel in sub queries so it may be worth a few simple 'show plan' tests.  As mentioned above ensuring you have the proper indexes would be my first step here as well.

Try using single quotes in your SQL query and also defining your column name:

 Query Q1(formal as %String) As %SQLQuery [ Final ]
{
    SELECT patientnumber, ID, 
    CASE
    WHEN ID = 50 THEN 'The is 50'
    WHEN ID = 30 THEN 'This is 30'
    ELSE 'The quantity is under 30'
    END
    As myValue 
    FROM Audit.Table WHERE ID = :formal AND EndDate is null

I implemented an excel export option for CCD activity dashboards many times.  Here is the generic javascript that you can find all over the web:

$(document).ready(function () {

    function exportTableToCSV($table, filename) {

        var $rows = $table.find('tr:has(td)'),

            // Temporary delimiter characters unlikely to be typed by keyboard
            // This is to avoid accidentally splitting the actual contents
            tmpColDelim = String.fromCharCode(11), // vertical tab character
            tmpRowDelim = String.fromCharCode(0), // null character

            // actual delimiter characters for CSV format
            colDelim = '","',
            rowDelim = '"\r\n"',

            // Grab text from table into CSV formatted string
            csv = '"' + $rows.map(function (i, row) {
                var $row = $(row),
                    $cols = $row.find('td');

                return $cols.map(function (j, col) {
                    var $col = $(col),
                        text = $col.text();

                    return text.replace(/"/g, '""'); // escape double quotes

                }).get().join(tmpColDelim);

            }).get().join(tmpRowDelim)
                .split(tmpRowDelim).join(rowDelim)
                .split(tmpColDelim).join(colDelim) + '"',

            // Data URI
            csvData = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csv);

        $(this)
            .attr({
            'download': filename,
                'href': csvData,
                'target': '_blank'
        });
    }

    // This must be a hyperlink
    $(".export").on('click', function (event) {
        // CSV
        exportTableToCSV.apply(this, [$('# directactivitytable>table'), 'export.csv']);
        
        // IF CSV, don't do event.preventDefault() or return false
        // We actually need this to be a typical hyperlink
    });
});

Here is the custom javascript where you need to reference your specific classes:

    $(".submit").on('click', function (event) {
         var activitytable #server(HIE.Test.CareConnect.Util.C5Dash.ActivityTable())#;
         $('#activitytable').html(activitytable);
         var inputBoxValue $('#query').val();
         var directactivitytable #server(HIE.Test.CareConnect.Util.C5Dash.DirectActivityTable(inputBoxValue))#;
         $('#directactivitytable').html(directactivitytable);
    });

And finally the div tags for a given webpage could be as follows:

            <div class="uk-grid" data-uk-grid-margin>
                <div class="uk-width-medium-1-1">
<hr class="uk-grid-divider">
             <form class="uk-form" >

<p>
<href="#" class="export">Export Table data into Excel</a>
</p>

</form>
                    <div class="uk-overflow-container">
                    <hr>
     <div id="directactivitytable"></div>
                    </hr>
                    </div>
                    </hr>
                </div>
            </div>