I'm currrently passing a data field into a custom visualisation of type 'Date'
I can see from the dataview in the custom vis toolbar that it is passed through as a bunch of functions and a epoch timestamp:
but when i try and log the same data from the options variable passed through to the public update function, i sse this:
what is going on here? and how do i successfully format that date as specified in the data model?
Hi @jonespossibly,
Can you please provide your capabilities.json with the objects removed, so I can see your dataRoles and dataViewMappings?
Can you also please provide details of which version of powerbi-visuals-tools and powerbi-visuals-api that you're using?
This is probably going to be the easiest way to replicate, unless you have a public repo you can share.
Thanks,
Daniel
Proud to be a Super User!
My course: Introduction to Developing Power BI Visuals
On how to ask a technical question, if you really want an answer (courtesy of SQLBI)
{ "dataRoles": [ { "displayName": "Summary Row fields", "name": "summaryRowColumn", "kind": "GroupingOrMeasure" }, { "displayName": "Detail Row HTML", "name": "detailHTML", "kind": "GroupingOrMeasure" } ], "dataViewMappings": [ { "conditions": [ { "detailHTML": { "max": 1 } } ], "categorical": { "categories": { "select": [ { "for": { "in": "summaryRowColumn" } }, { "for": { "in": "detailHTML" } } ] } } } ] }
Thanks - I was able to get your visual running and take a look 🙂
This is an interesting issue... it's the same in my visuals. So, probably a question for the team as to why it's the way it is. It doesn't make sense on the face of it, but both are valid if parsed.
In terms of formatting the date though, I usually test the metadata.type for the existence of the dateTime property, and instantiate a new Date() with the value if so (e.g. here).
This seems to work okay when formatting (using the format string in the format property):
So... sorry I can't answer why it's like that, but this might give you some ideas.
Regards,
Daniel
Proud to be a Super User!
My course: Introduction to Developing Power BI Visuals
On how to ask a technical question, if you really want an answer (courtesy of SQLBI)
Cheers Daniel.
And thanks for the code snippet. My main concern with the string values is that they use GMT and BST datetimes without an indication of them being part of that timezone.
So a date entered into power BI desktop, and set as a 'date' might be misinterpreted by a custom visual. So for instance, 01/01/2020 would come out as '2020-01-01T00:00:00.000Z' whereas 05/05/2019 would come through as '2019-05-04T23:00:00.000Z' - meaning that a custom visual might interpret that wrong. But I've just tried it through new Date and it seems like my worries were unfounded... 🙂
ok, this really is weird.
the data role of the well is "grouping".
if you put the date field into the well first, then it retains its date type functions.
if you put it in after another field, it turns the date types into strings.
what on earth???
Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!