Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Good day all,
Hope someone can help me with the following.
Below is a table with the total truck moves per appointment time and shift.
What I am looking for is the following:
Calculate the total truck moves within a shift, based on the present date and time.
For example:
The present date and time is: 2022-04-19 06:45
This means the present time is within the 00:00 – 07:15 shift
Power Bi then calculates the total truck moves in that particular shift: 56
Thanks upfront for your help!
John
Solved! Go to Solution.
Hi @Anonymous ,
According to my understanding, you want to get the sum value when the current time is in the period of [shift].
I have built a data sample, and on my side current time is 2022/4/22 2:32 PM
Please try to create a flag measure for visual-level filter later:
Flag =
var _now=HOUR(NOW()) *60 + MINUTE(NOW())
var _minShift= LEFT(MAX('Table'[shift]),5)
var _maxShift=RIGHT(MAX('Table'[shift]),5)
var _minSeconds= LEFT(_minShift,2) *60+RIGHT(_minShift,2)
var _maxSeconds= LEFT(_maxShift,2)*60+RIGHT(_maxShift,2)
return IF( _now>=_minSeconds && _now<=_maxSeconds && DATEDIFF(MAX('Table'[appointment_time]),TODAY(),DAY)=0 ,1,0)
Then calculate the sum:
Sum =
var _t= SUMMARIZE(FILTER( ALLSELECTED('Table'),[Flag]=1),[truck movement])
return SUMX(_t,[truck movement])
Output:
Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Glad it helps. From there you design according to what your dashboard needed.
If you are displaying in Table format, You can remove Shift from the formula. Group by shift under column, and you will get your subtotal automatically.
Appreciate if you could mark as solution if this helps out.
Hi @Anonymous ,
According to my understanding, you want to get the sum value when the current time is in the period of [shift].
I have built a data sample, and on my side current time is 2022/4/22 2:32 PM
Please try to create a flag measure for visual-level filter later:
Flag =
var _now=HOUR(NOW()) *60 + MINUTE(NOW())
var _minShift= LEFT(MAX('Table'[shift]),5)
var _maxShift=RIGHT(MAX('Table'[shift]),5)
var _minSeconds= LEFT(_minShift,2) *60+RIGHT(_minShift,2)
var _maxSeconds= LEFT(_maxShift,2)*60+RIGHT(_maxShift,2)
return IF( _now>=_minSeconds && _now<=_maxSeconds && DATEDIFF(MAX('Table'[appointment_time]),TODAY(),DAY)=0 ,1,0)
Then calculate the sum:
Sum =
var _t= SUMMARIZE(FILTER( ALLSELECTED('Table'),[Flag]=1),[truck movement])
return SUMX(_t,[truck movement])
Output:
Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
hi @Anonymous ,
I looked closely to your solution and it works fine for me.
Thanks a lot!
John
hi @Anonymous ,
I looked closely to your solution and it works fine for me.
Thanks a lot!
John
Glad it helps. From there you design according to what your dashboard needed.
If you are displaying in Table format, You can remove Shift from the formula. Group by shift under column, and you will get your subtotal automatically.
Appreciate if you could mark as solution if this helps out.
@Anonymous , Try a new column like
new column =
var _date = datevalue([appointment_time])
var _shift =[shift]
return
sumx(filter(Table, datevalue([appointment_time]) = _date && [shift] = _shift ), [truck moves])
Hope you were looking for a new column
Hi @amitchandak ,
Thanks for your reply.
Is it also possible add a formula, so power BI determines automatcally the correct shift, based on the present date and time?
Based on the table above (example):
The present (local date_time) is 19-04-2022 06:15
This means the outcome of the formula must be 56.
John
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!