Javascript array inside Tableau WDC connector:
[{Code: "AFG", Country: "Afghanistan", 1950: 20.249, 1951: 21.352, 1952: 22.532, 1953: 23.557, 1954: 24.555}, {Code: "ALB", Country: "Albania", 1950: 8.097, 1951: 8.986, 1952: 10.058, 1953: 11.123, 1954: 12.246}]
Lets asume that this is the output of javascript array which I get inside Tableau Desktop over WDC connector:
Code Country 1950 1951 1952 1953 1954
AFG Afghanistan 20,249 21,352 22,532 23,557 24,555
ALB Albania 8,097 8,986 10,058 11,123 12,246
Tableau doesnt allow pivoting table if datasource is WDC, so I need help how to writte/upgrade javascript code (inside my wdc code) to get output like this:
output array:
[{Code: "AFG", Country: "Afghanistan", Year: 1950, Value: 20.249}, {Code: "AFG", Country: "Afghanistan", Year: 1951, Value: 21.352}, {...}, {Code: "ALB", Country: "Albania", Year: 1950, Value: 8.097}, {Code: "ALB", Country: "Albania", Year: 1951, Value: 8.986}, {...}]
and to get output in Tableau Desktop like this:
Code Country Year Value
AFG Afghanistan 1950 20,249
AFG Afghanistan 1951 21,352
AFG Afghanistan 1952 22,532
AFG Afghanistan 1953 23,557
AFG Afghanistan 1954 24,555
ALB Albania 1950 8,097
ALB Albania 1951 8,986
ALB Albania 1952 10,058
ALB Albania 1953 11,123
ALB Albania 1954 12,246
In python, that is simple function called melt, but as I'm new into javascript I dont know how to perform this task/write correct code.
Thanks for advice and help.
Kind regards