Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
itsmebvk
Continued Contributor
Continued Contributor

Date Column Date (UTC) to Localtime (AEST) Issue

 

Hi Folks,

 

I am facing some date issue related to timezone.

 

I have a Date table (Azure analysis Service Model is source) in that table i have a Date column and other date related fields.  When I use Last 7 days filter in filters pane, even though I am on 28th its still showing days based on UTC time now. Instead of showing 21st to 27th its showing dates between 20th to 26th. (I understood based On Microsoft document Relative date filter works based UTC time)

 

itsmebvamsi_0-1674860889186.png

 

To fix this issue I tried to convert my Date column in power query to "Date/Time/Timezone", but when i try to filter my date using this new column it is still showing dates based on UTC. I tried most of the solutions suggested in the community.

 

itsmebvamsi_3-1674861457519.png

 

itsmebvamsi_4-1674861984511.png

 

I also tried to create calculated column using following expression but still same issue.

 

 

DateTimeZone.SwitchZone([Date],10)

 

 

 

I also checked AAS model, but there is no way i can convert it to "Date/Time/Timezone"

 

itsmebvamsi_5-1674862143971.png

 

Am i missing something here?  Is it because I i don't have time part in my Date or is there any setting in PBI Desktop overwriting this value?

 

Please suggest?

 

Thanks in advance.

 

 

 

 

 

 

6 REPLIES 6
olgad
Super User
Super User

Hi, 
what about adding 7 day filter in Power Query?
add column TodaysDate 
= Date.From(DateTimeZone.FixedUtcNow())
Change the data type to Date
then 

olgad_0-1675168135674.png

if [Date] <= [TodaysDate] then if [Date] >= Date.AddDays([TodaysDate] , -6) then 1 else 0 else 0

If today needs to be excluded then 
if [Date] <[TodaysDate] then if [Date] >= Date.AddDays([TodaysDate] , -7) then 1 else 0 else 0
And use it as a filter to filter for last 7 days. 


DID I ANSWER YOUR QUESTION? PLEASE MARK MY POST AS A SOLUTION! APPRECIATE YOUR KUDO/LIKE!
PROUD TO BE A SUPER USER!
Best Stories, Interesting Cases: PowerBI Storytime Newsletter
Linkedin Profile: Linkedin
YouTube Channel: PowerBI Storytime
OwenAuger
Super User
Super User

Hi there @itsmebvk 

This is a thorny problem with Power BI.

A couple of points to bear in mind:

  • As you've observed, in the Power BI Service, relative date slicers use current UTC date/time as the reference.
  • If timezone information is added to a datetime type column in Power Query (producing a datetimezone type) the column loaded to the Power BI dataset does not retain timezone in any way. Timezone information is basically discarded. A Power BI or Analysis Services dataset supports only datetime values without timezone information.

How to solve this?

Just to be clear on the requirements (hopefully I have this right 🙂 ), you want to take the current date in local time (UTC+10), then apply a filter corresponding to the 7 days preceding this.

So on 28-Jan in the UTC+10 timezone, the filter should be:

  • Dates in the range 21-Jan to 27-Jan
  • Or in terms of datetime, datetime values that are >= 21-Jan 0:00 and < 28-Jan 0:00.

Something to note about UTC & UTC+10:

  • In UTC+10, from 10:00 to just before 0:00, UTC+10 date = UTC date.
  • In UTC+10, from 0:00 to just before 10:00, UTC+10 date = UTC date + 1.

This means we can't rely on an additional column to help with filtering, because the inclusion of a given date varies during the day.

 

Instead, I would suggest creating a calculation group, with a calculation item that applies the filtering by converting UTC to local timezone.

The calculation item would have to

  • Determine LocalDate = UTCNOW() + 10 hours (just the date part).
  • Apply a filter on Calendar_Date, from LocalDate - 7 to LocalDate -1

The DAX expression for the calculation item would be:

 

 

VAR UTC_Offset_Hours = 10
VAR LocalDate =
    CONVERT (
        INT ( UTCNOW () + UTC_Offset_Hours / 24 ),
        DATETIME
    )
VAR MinDate =
    LocalDate - 7
VAR MaxDate =
    LocalDate - 1
VAR Result =
    CALCULATE (
        SELECTEDMEASURE (),
        DATESBETWEEN ( 'Dim_Date'[Calendar_Date], MinDate, MaxDate )
    )
RETURN
    Result

 

 

Then apply this calculation item as a filter on the page or visuals as required. Note that this only applies to the calculation of measures, so I am assuming that this is sufficient for the visuals you are creating.

 

If you're new to calculation groups, check out SQLBI's series of articles.

 

Hopefully this is useful. Please post back if needed.

 

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn
itsmebvk
Continued Contributor
Continued Contributor

Thanks @olgad @OwenAuger fro your inputs.

 

With your direction I am able to achieve my requirement in slightly different way. I created an import table using following expression and filtered using that column. That solved my issue .

 

 

 

define var utctime = now()
       var correcteddate = datevalue(utctime+(11/24)) 
       var _Previous7thday =  correcteddate -7
       var _Yesterday=  correcteddate -1

evaluate

summarize(
          calculatetable(Dim_Date
			,Dim_Date[Date]>=_Last7thday
                        ,Dim_Date[Date]<=_Yesterday)
			,Dim_Date[Date])
						
						 
order by Dim_Date[Date] desc

 

 

 

Really appreciate for your direction.

itsmebvk
Continued Contributor
Continued Contributor

 

 

@OwenAuger ,

 

Thanks alot for taking time and sharing your inputs.

 

Sorry I didnt understand how we need to filter on visual or page using the measure you suggested. New is the measure which i created, Can you please suggest what we need to filter here?

 

itsmebvamsi_0-1675117381583.png

 

Thanks in advance.

 

Hi @itsmebvk 

No problem 🙂
Just to clarify, I was suggesting creating a Calculation Group and that code was for a Calculation Item within the Calculation Group.

 

See here for the general method to create these.

https://learn.microsoft.com/en-us/training/modules/dax-power-bi-calculation-groups/calculation-group...

 

Once created, you can apply a filter on the column of the Calculation Group table for the specific Calculation Item.

 

Regards,

Owenn


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn
itsmebvk
Continued Contributor
Continued Contributor

Hi Folks,

 

Can you please share your thoughts around this issue?

 

Thanks in advance.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.