I use pluck(data(‘thedata’) , ‘gender’)
and get an array of all the values from ‘thedata'[‘gender’]
like male, female, male, female …
but what I want is this
male,female
even better I want it sorted like so
female, male
I want this as an extra column in the original table and ideally grouped by brand.
This is what I have:
{ "width": 300,
//taken from here: /questions/3309805/what-regular-expression-can-remove-duplicate-items-from-a-string
//Perl
//b(w+):(?=.*b1:?)
//dotnet
//(?<=b1:.*)b(w+):?
//]
"params": [
{
"name": "mySearchPattern", "value": "\b(\w+),(?=.*\b\1,?)"
}
],
"data":
{"name": "thedata",
"values": [
{"brand": "this", "gender": "male", "Sales": 1000, "PY": 900, "Plan": 950},
{"brand": "this", "gender": "female", "Sales": 200, "PY": 50, "Plan": 50},
{"brand": "that", "gender": "male", "Sales": 500, "PY": 400, "Plan": 450},
{"brand": "that", "gender": "female", "Sales": 1000, "PY": 800, "Plan": 700},
{"brand": "something", "gender": "female", "Sales": 500, "PY": 100, "Plan": 400},
{"brand": "something", "gender": "male", "Sales": 20, "PY": 20, "Plan": 40}
]
},
"transform":[
{"calculate": "slice(['female', 'male'], indexof(['female', 'male'], datum['gender']), indexof(['female', 'male'], datum['gender'])+1)",
"as": "testing"
},
{"calculate": "pluck(data('thedata'), 'gender')",
"as": "allvalues"
}
,
{"calculate": "regexp(mySearchPattern , datum['contentofGender'])",
"as": "myregexp"
}
]
,"mark":
{
"type": "bar"
},
"encoding": {
"y": {"field": "brand", "type": "nominal"},
"x": {
"field": "Sales", "type": "quantitative"
}
}
}
But I do not understand how to pass the gender to regexp to the regexp pattern.
And probably there is much more elegant way to get the distinct values from a column and get it sorted._