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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Matt_dev
Frequent Visitor

DAX Issue

Hi,

 

I have the following DAX (credit https://addendanalytics.com/blog/calculate-working-hours-in-power-bi) which creates a time from hours and minutes between 06:00 and 23:59 and I want to make a small change:

 

var Hours_List = SELECTCOLUMNS(GENERATESERIES((6), (23)), “Hour”, [Value])

var Minutes_List = SELECTCOLUMNS(GENERATESERIES((0), (59)), “Minute”, [Value])

var two_years_ago_start = DATE(YEAR(NOW())-2,1,1) //DATE(2018,1,1)

var one_year_later_end = DATE(YEAR(NOW())+1,12,31)

var Dates_List = CALENDAR(two_years_ago_start,one_year_later_end)

var HoursandMinutes = ADDCOLUMNS(

CROSSJOIN(Hours_List, Minutes_List),

“Time”, TIME([Hour], [Minute], 00),

“Validity”, IF([Hour]<6 || [Hour]>23,”Non working”,”Working”)

)

 

I would like the list to stop at 23:45 but only for hour 23. I want the window to be 06:00 to 23:45 but still count the last 15 minutes in all other hours. My instinct is to use an IF on the ADDCOLUMNS function used in setting the variable HoursandMinutes but I'm not sure exactly what it would look like as I am used to managing these changes in SQL where I would say:

 

WHERE NOT (Hours_List = 23 AND Minutes_List > 44) 

Any help would be wonderful

 

Thanks in advance

 

Matt 

 

 

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi  , 

Just add a filter function to the HoursandMinutes something similar to this:

 

Hour minutes tables = var Hours_List = SELECTCOLUMNS(GENERATESERIES((6), (23)), "Hour", [Value])

var Minutes_List =  SELECTCOLUMNS(GENERATESERIES((0), (59)), "Minute", [Value])

var two_years_ago_start = DATE(YEAR(NOW())-2,1,1) //DATE(2018,1,1)

var one_year_later_end = DATE(YEAR(NOW())+1,12,31)

var Dates_List = CALENDAR(two_years_ago_start,one_year_later_end)

var HoursandMinutes = ADDCOLUMNS(

CROSSJOIN(Hours_List, Minutes_List),

"Time", TIME([Hour], [Minute], 00),

"Validity", IF([Hour]<6 || [Hour]>23,"Non working","Working")

)

VAR HourMinutes_23_45 = FILTER( HoursandMinutes, [Time] <= TIME(23,45,00))
RETURN
HourMinutes_23_45

 

See in the filter below that for 23 you only get untilm 23:45 for the rest of the hours you have until minute 59

MFelix_1-1760801149336.png

MFelix_3-1760801238933.png

@Matt_dev


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

3 REPLIES 3
MFelix
Super User
Super User

Hi  , 

Just add a filter function to the HoursandMinutes something similar to this:

 

Hour minutes tables = var Hours_List = SELECTCOLUMNS(GENERATESERIES((6), (23)), "Hour", [Value])

var Minutes_List =  SELECTCOLUMNS(GENERATESERIES((0), (59)), "Minute", [Value])

var two_years_ago_start = DATE(YEAR(NOW())-2,1,1) //DATE(2018,1,1)

var one_year_later_end = DATE(YEAR(NOW())+1,12,31)

var Dates_List = CALENDAR(two_years_ago_start,one_year_later_end)

var HoursandMinutes = ADDCOLUMNS(

CROSSJOIN(Hours_List, Minutes_List),

"Time", TIME([Hour], [Minute], 00),

"Validity", IF([Hour]<6 || [Hour]>23,"Non working","Working")

)

VAR HourMinutes_23_45 = FILTER( HoursandMinutes, [Time] <= TIME(23,45,00))
RETURN
HourMinutes_23_45

 

See in the filter below that for 23 you only get untilm 23:45 for the rest of the hours you have until minute 59

MFelix_1-1760801149336.png

MFelix_3-1760801238933.png

@Matt_dev


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Thank you Miguel, that has worked perfectly 

Hi @Matt_dev ,

 

Don't forget to accept the correct answer so it can help out others.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.