Forum Discussion

speedyspeedstar's avatar
speedyspeedstar
Regular Visitor
8 years ago
Solved

Power BI Embedded DateTime Json filter translates to UTC+10

I have imported some date-times from SQL Server e.g.

 

2016-12-07 00:00:00.000
2016-06-08 00:00:00.000
2016-01-20 00:00:00.000

 

The import works fine and in Power BI Desktop/service I can see that the data is unmodified.

 

I have embedded this report into an MVC app and I pass along a filter constructed as so

 

[{
$schema:"http://powerbi.com/product/schema#advanced",
target:{table:"ReportingClientActivityReport",column:"InvoiceDate"},
logicalOperator:"And",
conditions:
[{operator:"LessThanOrEqual",value:"2017-10-22 00:00:00Z"},
{operator:"GreaterThanOrEqual",value:"2017-10-16 00:00:00Z"}]
}]

I put this filter into an embedded iframe and then pass it along to Power BI and at some point power BI has seen fit to translate my filter to UTC+10 (I get 2017-10-22 10:00:00Z and 2017-10-16 10:00:00Z) This is most likely because the server that's embedding the report is in Brisbane (UTC+10)

 

Is there a way I can get power BI to recognise my date-time as having already been translated to timezone?

  • Eric_Zhang's avatar
    Eric_Zhang
    8 years ago

    speedyspeedstar wrote:

    My data is imported from SQL with date/time data i.e.


    2016-12-07 00:00:00.000
    2016-06-08 00:00:00.000
    2016-01-20 00:00:00.000

     

    and Power BI Desktop and service interprets this correctly.

     

    I embed the report into an MVC application application and I construct this filter :

     

    [
    {$schema:"http://powerbi.com/product/schema#advanced",
    target {table:"ReportingClientActivityReport",column:"InvoiceDate"},
    logicalOperator:"And",
    conditions:
    [{operator:"LessThanOrEqual",value:"2017-10-22 00:00:00Z"},
    {operator:"GreaterThanOrEqual",value:"2017-10-16 00:00:00Z"}]} ]

    I put this filter in the json object for the power BI embedded iframe but when my embedded report comes back it's filtered to UTC+10 (server is in Brisbane)

     

    How do I communicate in the filter that I want this particular DateTime without offset


    speedyspeedstar

    The datetime format trailed with "Z" indicates a UTC format, based on my test, to get the server local datetime, you just remove the trailing "Z".

    [
    {$schema:"http://powerbi.com/product/schema#advanced",
    target {table:"ReportingClientActivityReport",column:"InvoiceDate"},
    logicalOperator:"And",
    conditions:
    [{operator:"LessThanOrEqual",value:"2017-10-22 00:00:00"},
    {operator:"GreaterThanOrEqual",value:"2017-10-16 00:00:00"}]}
    ]

    See my test without VS with trailing "Z"

3 Replies

    • Eric_Zhang's avatar
      Eric_Zhang
      Icon for Microsoft Employee rankMicrosoft Employee

      speedyspeedstar wrote:

      My data is imported from SQL with date/time data i.e.


      2016-12-07 00:00:00.000
      2016-06-08 00:00:00.000
      2016-01-20 00:00:00.000

       

      and Power BI Desktop and service interprets this correctly.

       

      I embed the report into an MVC application application and I construct this filter :

       

      [
      {$schema:"http://powerbi.com/product/schema#advanced",
      target {table:"ReportingClientActivityReport",column:"InvoiceDate"},
      logicalOperator:"And",
      conditions:
      [{operator:"LessThanOrEqual",value:"2017-10-22 00:00:00Z"},
      {operator:"GreaterThanOrEqual",value:"2017-10-16 00:00:00Z"}]} ]

      I put this filter in the json object for the power BI embedded iframe but when my embedded report comes back it's filtered to UTC+10 (server is in Brisbane)

       

      How do I communicate in the filter that I want this particular DateTime without offset


      speedyspeedstar

      The datetime format trailed with "Z" indicates a UTC format, based on my test, to get the server local datetime, you just remove the trailing "Z".

      [
      {$schema:"http://powerbi.com/product/schema#advanced",
      target {table:"ReportingClientActivityReport",column:"InvoiceDate"},
      logicalOperator:"And",
      conditions:
      [{operator:"LessThanOrEqual",value:"2017-10-22 00:00:00"},
      {operator:"GreaterThanOrEqual",value:"2017-10-16 00:00:00"}]}
      ]

      See my test without VS with trailing "Z"

      • speedyspeedstar's avatar
        speedyspeedstar
        Regular Visitor

        Awesome I'll give it a go tomorrow and let you know how it goes :)

         

        edit : Works great! For C# devs with the same problem, you can use

         

                public static string ToPowerBIDate(this DateTime src)
                {
                    return src.ToString("s");
                }

        as an extension method to get local time, if you want UTC then just transform src with ToUniversalTime() and then ToString("u")