Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hello. I am creating a dashboard using a direct query from SQL, with automatic page refresh when a change is detected. Because I am using direct query, I can do very little transformation in Power Query. And because I am using automatic page refreshes, I cannot use calculated tables or columns because then the visuals do not refresh when a change is detected.
I have one measure to convert the time from UTC to local (local date = Selectedvalue(table[date/time]) +TIME(6,0,0).
However, I need a way to condition this statement so if the date falls within daylight savings time ( Mar 2nd Sunday-Nov 1st Sunday), the measure will only add 5 hours . Is this possible? I found several articles on how to do this in power query, but I cannot use power query for this.
I have tried a similar solutions from Solved: Measure to Convert UTC to local time, accounting f... - Microsoft Fabric Community
But it wont fit my requirement as the Day light savings should end on Nov 1st sunday.
My
First condtion will be If date is from Mar 2nd Sunday to Nov 1st sunday then + 5 hours
Second condition will be if date is after Nov 1st sunday to before Mar 2nd sunday then +6 hours.
I have tried the code which is only working for my first condtion
Measure =
VAR _table =
ADDCOLUMNS(
ALL(DateTable[Date]),
"Day",
WEEKDAY(DateTable[Date], 2),
"Month",
MONTH(DateTable[Date])
)
VAR _table1 =
FILTER(
_table,
[Month]=3&&[Day] = 7
)
VAR _shiftdate =
EXCEPT(
TOPN(
2,
_table1,
DateTable[Date],
ASC
),
TOPN(
1,
_table1,
DateTable[Date],
ASC
)
)
VAR _shiftdate2 = MINX(_shiftdate, [Date])
RETURN
IF(
MAX([Date])<_shiftdate2,
MAX([Date]) + TIME(6,0,0),
MAX([Date]) + TIME(5,0,0)
)
If anyone can help me rewrite the code then it would be a great help
Thanks in Advance.
Solved! Go to Solution.
Hi @Powerbi_user26 ,
Please update the formula of measure as below and check if it can return the expected result...
MEASURE =
VAR _table =
ADDCOLUMNS (
ALL ( 'Table'[Date] ),
"DayOfWeek", WEEKDAY ( 'Table'[Date], 2 ),
"Month", MONTH ( 'Table'[Date] ),
"Year", YEAR ( 'Table'[Date] )
)
VAR _year =
YEAR ( MAX ( OMTLiveTask[ScheduledStartDateTime] ) )
VAR _marchfirst =
DATE ( _year, 3, 1 )
VAR _firstsunday =
_marchfirst - WEEKDAY ( _marchfirst, 2 ) + 7
VAR _secondSundayInMarch = _firstsunday + 7
VAR _firstSundayInNovember =
CALCULATE (
MIN ( 'Table'[Date] ),
FILTER ( _table, [Month] = 11 && [DayOfWeek] = 7 && [Year] = _year )
)
RETURN
IF (
MAX ( OMTLiveTask[ScheduledStartDateTime] ) >= _secondSundayInMarch
&& MAX ( OMTLiveTask[ScheduledStartDateTime] ) < _firstSundayInNovember,
MAX ( OMTLiveTask[ScheduledStartDateTime] ) + TIME ( 5, 0, 0 ),
MAX ( OMTLiveTask[ScheduledStartDateTime] ) + TIME ( 6, 0, 0 )
)
Best Regards
Hi @Nivi_N_26 ,
Please update the formula of your measure as below and check if it can return your expected result.
MEASURE =
VAR _table =
ADDCOLUMNS (
ALL ( DateTable[Date] ),
"DayOfWeek", WEEKDAY ( DateTable[Date], 2 ),
"Month", MONTH ( DateTable[Date] ),
"Year", YEAR ( DateTable[Date] )
)
VAR _secondSundayInMarch =
CALCULATE (
MIN ( 'Table'[Date] ),
FILTER (
_table,
[Month] = 3
&& [DayOfWeek] = 7
&& [Year] = YEAR ( MAX ( 'Table'[Date] ) )
)
)
VAR _firstSundayInNovember =
CALCULATE (
MIN ( 'Table'[Date] ),
FILTER (
_table,
[Month] = 11
&& [DayOfWeek] = 7
&& [Year] = YEAR ( MAX ( 'Table'[Date] ) )
)
)
RETURN
IF (
MAX ( [Date] ) >= _secondSundayInMarch
&& MAX ( [Date] ) < _firstSundayInNovember,
MAX ( [Date] ) + TIME ( 5, 0, 0 ),
MAX ( [Date] ) + TIME ( 6, 0, 0 )
)
Best Regards
Hi @v-yiruan-msft ,
I have used your dax and it works, but it is picking only the first sunday of march and first sunday in november.
It should be second sunday in March.
Hi @Powerbi_user26 ,
Please update the formula of measure as below and check if it can return the expected result...
MEASURE =
VAR _table =
ADDCOLUMNS (
ALL ( 'Table'[Date] ),
"DayOfWeek", WEEKDAY ( 'Table'[Date], 2 ),
"Month", MONTH ( 'Table'[Date] ),
"Year", YEAR ( 'Table'[Date] )
)
VAR _year =
YEAR ( MAX ( OMTLiveTask[ScheduledStartDateTime] ) )
VAR _marchfirst =
DATE ( _year, 3, 1 )
VAR _firstsunday =
_marchfirst - WEEKDAY ( _marchfirst, 2 ) + 7
VAR _secondSundayInMarch = _firstsunday + 7
VAR _firstSundayInNovember =
CALCULATE (
MIN ( 'Table'[Date] ),
FILTER ( _table, [Month] = 11 && [DayOfWeek] = 7 && [Year] = _year )
)
RETURN
IF (
MAX ( OMTLiveTask[ScheduledStartDateTime] ) >= _secondSundayInMarch
&& MAX ( OMTLiveTask[ScheduledStartDateTime] ) < _firstSundayInNovember,
MAX ( OMTLiveTask[ScheduledStartDateTime] ) + TIME ( 5, 0, 0 ),
MAX ( OMTLiveTask[ScheduledStartDateTime] ) + TIME ( 6, 0, 0 )
)
Best Regards
Thank you so much it worked
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
147 | |
85 | |
66 | |
52 | |
46 |
User | Count |
---|---|
215 | |
90 | |
83 | |
66 | |
58 |