<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Custom Visual - Accepting the Data Modelling Date Format in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Custom-Visual-Accepting-the-Data-Modelling-Date-Format/m-p/850375#M21476</link>
    <description>&lt;P&gt;Thanks &lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/397"&gt;@dm-p&lt;/a&gt;!&lt;/P&gt;&lt;P&gt;What I'm struggling with is applying that format value to the x-axis label for the date.&lt;/P&gt;&lt;P&gt;When setting the x-axis text, I'm using the values from the category but they still just display as a full date string like "Sat Sep 23 2017 00:00:00 GMT-0400 (Eastern Daylight Time)"&lt;/P&gt;&lt;P&gt;Is there a trick to apply that format variable to the values in the category so that my x-axis labels display with that format?&lt;/P&gt;</description>
    <pubDate>Tue, 19 Nov 2019 14:57:01 GMT</pubDate>
    <dc:creator>mattapq</dc:creator>
    <dc:date>2019-11-19T14:57:01Z</dc:date>
    <item>
      <title>Custom Visual - Accepting the Data Modelling Date Format</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Custom-Visual-Accepting-the-Data-Modelling-Date-Format/m-p/847627#M21423</link>
      <description>&lt;P&gt;In the Desktop version of Power BI, you can select a Date field and in the ribbon you can change the Modelling &amp;gt; Format of the date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DateFormatting.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/209243i050A872BE7925940/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DateFormatting.png" alt="DateFormatting.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the default Power BI line chart, this changes the x-axis dates to match your selected formatting. I can't recreate this functionality in my custom visual though. Is this chosen formatting somehow accessible from the visual's code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My visual is using a categorical data model, the x-axis is a Time scale, and the dates are not being formatted manually in the visual's code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;EDIT&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;For anyone that stumbles into this post with this problem or a similar one, I'm using d3 5.7.2 and version 2.5.0 of the Power BI API. I just had to do the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Install the&amp;nbsp;&lt;SPAN&gt;powerbi-visuals-utils-formattingutils library&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2. Create a formatter and set its "format" property to the format we pulled from the categories source, i.e.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; myFormatter = valueFormatter.create({format:&amp;nbsp;dataViews[0].categorical.categories[0].source.format});&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3. Format your value:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; formattedDate = formatter.format(myDate);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;4. Use this new formatted date as the x-axis label value instead of the date itself.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2019 12:57:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Custom-Visual-Accepting-the-Data-Modelling-Date-Format/m-p/847627#M21423</guid>
      <dc:creator>mattapq</dc:creator>
      <dc:date>2019-11-21T12:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Visual - Accepting the Data Modelling Date Format</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Custom-Visual-Accepting-the-Data-Modelling-Date-Format/m-p/849337#M21455</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/148811"&gt;@mattapq&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;If you check the categorical column definition in the data view, there is a format property exposed under the higher-level source property, e.g.:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 451px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/209793i01294818435DCA02/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;If your fields doesn't have a format applied to it, this will just say "G" instead of the applied format.&lt;/P&gt;&lt;P&gt;Assuming that you're working with a single category field, you'd access with &lt;FONT face="courier new,courier"&gt;dataViews[0].categorical.categories[0].source.format&lt;/FONT&gt; when resolving your formatting. If you are iterating through categories when mapping it would just be &lt;FONT face="courier new,courier"&gt;current category variable name.source.format&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;Good luck!&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2019 19:28:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Custom-Visual-Accepting-the-Data-Modelling-Date-Format/m-p/849337#M21455</guid>
      <dc:creator>dm-p</dc:creator>
      <dc:date>2019-11-18T19:28:56Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Visual - Accepting the Data Modelling Date Format</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Custom-Visual-Accepting-the-Data-Modelling-Date-Format/m-p/850375#M21476</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/397"&gt;@dm-p&lt;/a&gt;!&lt;/P&gt;&lt;P&gt;What I'm struggling with is applying that format value to the x-axis label for the date.&lt;/P&gt;&lt;P&gt;When setting the x-axis text, I'm using the values from the category but they still just display as a full date string like "Sat Sep 23 2017 00:00:00 GMT-0400 (Eastern Daylight Time)"&lt;/P&gt;&lt;P&gt;Is there a trick to apply that format variable to the values in the category so that my x-axis labels display with that format?&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2019 14:57:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Custom-Visual-Accepting-the-Data-Modelling-Date-Format/m-p/850375#M21476</guid>
      <dc:creator>mattapq</dc:creator>
      <dc:date>2019-11-19T14:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Visual - Accepting the Data Modelling Date Format</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Custom-Visual-Accepting-the-Data-Modelling-Date-Format/m-p/850722#M21483</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/148811"&gt;@mattapq&lt;/a&gt;&amp;nbsp;- fundamentally, you just need to install &lt;A href="https://github.com/microsoft/powerbi-visuals-utils-formattingutils/blob/master/docs/usage/installation-guide.md" target="_self"&gt;powerbi-visuals-utils-formattingutils&lt;/A&gt; to your project and using &lt;A href="https://github.com/microsoft/powerbi-visuals-utils-formattingutils/blob/master/docs/api/value-formatter.md" target="_self"&gt;valueFormatter&lt;/A&gt; but it's also going to&amp;nbsp;depend on you've chosen to implement your code. For instance, if you're using v3 of the visuals SDK vs. 1/2, or whether you're using D3 to do your chart, or something else.&lt;/P&gt;&lt;P&gt;D3 v3 (which is supported by the older SDKs) can handle the format strings as standard but some stuff changed in v4/5 and the v3 SKD recommends that version. The implementation of axis tick formatting is a little different for those, so I just want to make sure I provide you with more targeted advice, if possible. I can definitely help with D3 but if it's something else I might need to do a bit of digging.&lt;/P&gt;&lt;P&gt;If you're able to share anything code-wise, I can take a look for you and provide something that will hopefully get you on the path to your desired solution.&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2019 18:58:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Custom-Visual-Accepting-the-Data-Modelling-Date-Format/m-p/850722#M21483</guid>
      <dc:creator>dm-p</dc:creator>
      <dc:date>2019-11-19T18:58:54Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Visual - Accepting the Data Modelling Date Format</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Custom-Visual-Accepting-the-Data-Modelling-Date-Format/m-p/853055#M21510</link>
      <description>&lt;P&gt;That library was the missing piece of the puzzle. Thanks,&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/397"&gt;@dm-p&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For anyone that stumbles into this post with this problem or a similar one, I'm using d3 5.7.2 and version 2.5.0 of the Power BI API. I just had to do the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Install the&amp;nbsp;&lt;SPAN&gt;powerbi-visuals-utils-formattingutils library&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2. Create a formatter and set its "format" property to the format we pulled from the categories source, i.e.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; myFormatter = valueFormatter.create({format:&amp;nbsp;&lt;SPAN&gt;dataViews[0].categorical.categories[0].source.format});&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;3. Format your value:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; formattedDate = formatter.format(myDate);&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;4. Use this new formatted date as the x-axis label value instead of the date itself.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2019 12:54:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Custom-Visual-Accepting-the-Data-Modelling-Date-Format/m-p/853055#M21510</guid>
      <dc:creator>mattapq</dc:creator>
      <dc:date>2019-11-21T12:54:05Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Visual - Accepting the Data Modelling Date Format</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Custom-Visual-Accepting-the-Data-Modelling-Date-Format/m-p/853314#M21517</link>
      <description>Awesome - glad you're all sorted! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Thu, 21 Nov 2019 16:47:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Custom-Visual-Accepting-the-Data-Modelling-Date-Format/m-p/853314#M21517</guid>
      <dc:creator>dm-p</dc:creator>
      <dc:date>2019-11-21T16:47:48Z</dc:date>
    </item>
  </channel>
</rss>

