Inserting array into listobjects().listcolums().databodyrange - arrays

A fast way of transfering data between Excel tables is to read the data into an array by looping thru the source table and then insert them into the destination table in one command. This works fine for the table databodyrange; listobjects().databodyrange = aTransfer. But when trying out doing the same for listcolumns; listobjects().listcolumns().databodyrange = aTransfer, the first number in the column is repeated down to the end of the column.
This is demonstrated in this example: Transfering data between tables
Is there a way of getting around this?

You'll need to transpose your one-dimensional horizontal array into a vertical one using the Transpose method of the Application object. Here's an example...
Worksheets("Sheet1").ListObjects("Table1").ListColumns(1).DataBodyRange.Value = application.transpose(aTransfer)

Related

Big query nested json strings to arrays then new tables

Bigquery Database
I've got a webhook that's pushing to my big query table. The problem is it has lots of nested json strings which are brought in as strings. I ultimately want to make each column with these json strings into their own tables but I'm getting stuck because I can't figure out how to get them unnested and into an array.
[{"id":"63bddc8cfe21ec002d26b7f4","description":"General Admission", "src_currency":"USD","src_price":50.0,"src_fee":0.0,"src_commission":1.79,"src_discount":0.0,"applicable_pass_id":null,"seats_label":null,"seats_section_label":null,"seats_parent_type":null,"seats_parent_label":null,"seats_self_type":null,
"seats_self_label":null,"rate_type":"Rate","option_name":null,"price_level_id":null,"src_discount_price":50.0,"rate_id":"636d6d5cea8c6000222c640d","cost_item_id":"63bddc8cfe21ec002d26b7f4"}]
Here's the sample return from the original source and below is a screenshot of what I'm working with.
[Current Database
I've tried a number of things but the multiple nestings and string to array issue are really hampering everything I've tried.
I'm honestly not sure exactly what output/structure is best for this data set. I assume that each of the json returns probably just needs to be its own table and I can reference or join them based off that first "id" value in the json strings but I'm wide open to suggestions.
You can use a combination of JSON functions, and array functions to manipulate this kind of data.
JSON_EXTRACT_ARRAY can convert the JSON formatted string into an array, UNNEST then can make each entry into rows, and finally JSON_EXTRACT_SCALAR can pull out individual columns.
So here's an example of what I think you're trying to accomplish:
with sampledata as (
select """[{"id":"63bddc8cfe21ec002d26b7f4","description":"General Admission", "src_currency":"USD","src_price":50.0,"src_fee":0.0,"src_commission":1.79,"src_discount":0.0,"applicable_pass_id":null,"seats_label":null,"seats_section_label":null,"seats_parent_type":null,"seats_parent_label":null,"seats_self_type":null,"seats_self_label":null,"rate_type":"Rate","option_name":null,"price_level_id":null,"src_discount_price":50.0,"rate_id":"636d6d5cea8c6000222c640d","cost_item_id":"63bddc8cfe21ec002d26b7f4"},{"id":"63bddc8cfe21ec002d26b7f4","description":"General Admission", "src_currency":"USD","src_price":50.0,"src_fee":0.0,"src_commission":1.79,"src_discount":0.0,"applicable_pass_id":null,"seats_label":null,"seats_section_label":null,"seats_parent_type":null,"seats_parent_label":null,"seats_self_type":null,"seats_self_label":null,"rate_type":"Rate","option_name":null,"price_level_id":null,"src_discount_price":50.0,"rate_id":"636d6d5cea8c6000222c640d","cost_item_id":"63bddc8cfe21ec002d26b7f4"}]""" as my_json_string
)
select JSON_EXTRACT_SCALAR(f,'$.id') as id, JSON_EXTRACT_SCALAR(f,'$.rate_type') as rate_type, JSON_EXTRACT_SCALAR(f,'$.cost_item_id') as cost_item_id
from sampledata, UNNEST(JSON_EXTRACT_ARRAY(my_json_string)) as f
Which creates rows with specific columns from that data, like this:

SAS arrays to fill the last value carry forward across multiple columns

As mentioned in the picture sepstrata0, sepstrata1,sepstrata3 have already the last values slong with YAS,YES,YCS columns. I would like to change the code such a way that the sepstrata0, sepstrata1,sepstrata3 columns remain unaffected while other columns coming from transposed_gen_mod should have the LVCF. I've YAS0 YES0 YCS0 YAS1 YES1 YCS1 YAS3 YES3 YCS3 columns where I have values such as "Atrisk" in all YAS columns, similarly "Events" for YES columns and "Censor" for all YCS columns and total I've about 9547 rows and only 1st rows of each column has the values. I would like to caryy forword the values to all 9657 rows.
Could anyone guide me though how to modify the below written code to achieve the results. I have tried to do it through do over loop but couldn't finish it till end.Let me know if i'm on track and help with a solution to modify the code to achieve the results.
data plot_data_fin;
merge plot_datafin transposed_gen_mod;
by row;hw_lcl_lag=lag(hw_lcl);
ARRAY cols {*} YAS: YES: YCS: ;
Do i=1 to dim(cols);
if COLS[i]=" " then COLS[i]=lag(COLS[i]);
end;
run;
run;
If transposed_gen_mod only has one row with YAS etc. columns, and you want to add those values in to every row on plot_datafin, then you can just merge without a by variable.
data plot_data_fin;
merge plot_data_fin transposed_gen_mod;
run;
You will get a warning in the log about merging without a by variable, but the result will be correct.
It is unclear how your data is structured so it is hard to answer the question coherently.

Handling new line in column value of HIVE AVRO format table - contains complex data type & nested arrays

I have an HIVE table which is AVRO format and one of the column in the table contains complex data type (nested arrays). One of the element in that nested array contains data which contains new line characters. I am using multiple lateral view explode to flatten the data; but because of the new line character in one of the columns the output is not good (means it is mapping wrong value against wrong column). I tried to use regex_replace function in my query by it is told a invalid function. I am using "Hive 1.1.0-cdh5.12.2". Can you please tell me how could I handle this new line issue within the data while querying from the avro table using multiple laterview explode (as there are nested arrays).

Make cells that were populated with Concentrate function have standalone data instead of the formula

Below I have linked my CSV for a store (woocommerce), I have columns C and D pulling data from other columns. So when I export as CSV and upload to woocommerce the data from those cells isn't represented correctly, what I need to do is make those cells actually contain the text that is displayed using the concentrate function.
Is there an easy way to go about this, or am I bound to copy paste from two columns and add text that repeats?
https://docs.google.com/spreadsheets/d/189DoiV2LwV5JrXqPVAZTL9ww5hAq2Ws7_IdWqsd7mqo/edit?usp=sharing
I have figured it out. I have selected the whole column that used the formula to generate the value (text) and copied it, then I have pasted it somewhere else in the same document, deleted the original column and pasted the value column in its place.

Table Manipulations in Excel VBA

I have the following table on one sheet, top table of the picture, and I need to transform it to the to the different format on the second sheet (bottom table of the picture). I need to use VBA in Excel to do this manipulations. I pulled the main table (top) from SQL query on the separate sheet and need to rearrange it to fit my needs. I have a lot more data than that but it follows the same format. Just imagine that there are just more Shelves, Items, Amounts and Stores.
I searched everywhere but can't seem to find direct answer.
I am relatively new to VBA. Can someone give me a some directions? Is there a website with some tutorials about table manipulations in Excel VBA?
Beyond an intellectual pursuit, there is absolutely no need for VBA. From your example, put this array formula in C24.
=IFERROR(INDEX($B$2:$B$23, MATCH(0, IF(LEN($B$2:$B$23), COUNTIF($B24:B24, $B$2:$B$23), 1), 0)), "")
Finalize with Ctrl+Shift+Enter↵. Once entered correctly, fill right until you run out of values to retrieve.
In A25 use this standard formula.
=IF(COUNTIF(A$24:A24, MOD(ROW(1:1)-1, MAX(A$2:A$23))+1)<SUMPRODUCT((D$2:D$23<>"")/COUNTIF(D$2:D$23, D$2:D$23&"")), MOD(ROW(1:1)-1, MAX(A$2:A$23))+1, "")
Fill down to get all of the shelves you will need.
In B25 use this array formula,
=IF(AND(ROW(1:1)>1,COUNTIF(A$24:A25, A25)=COUNTIF(A$24:A24, A24)), B24, IFERROR(INDEX($D$2:$D$23, MATCH(0, IF(LEN($D$2:$D$23), COUNTIF(B$24:B24, $D$2:$D$23), 1), 0)), ""))
Finalize with Ctrl+Shift+Enter↵. Fill down to catch all of the stores.
Finally, put this in C25.
=SUMIFS($C$2:$C$23, $A$2:$A$23, $A25, $B$2:$B$23, C$24, $D$2:$D$23, $B25)
Fill right to D25 then fill C25:D25 down to the length of the table.
                  
The only difference in my second table is that Water comes before Gartorade and that is a result of it appearing the first table's Item list first.

Resources