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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Using DAX to calculate the total free hours between dates

Good day to anyone who reads this,

I am a student taking my first steps with dax and power BI for a Data analyst internship and i've ran into a little problem I'm currently trying to figure out how to use Dax to calculate the amount of time someone got off work. These hours are calculated from the days between a start date and end date with another collumn showing how many hours per day they had off work(see excel recreation below) 

Morth_0-1681980885930.png

I've been looking around how to get this to work with DAX and I've tried to use the following code as a first step to count the amount of days between the two dates but got no results.

 

 

Days =

DATEDIFF(
	SELECTEDVALUE( TT_EMP_BOOK[TT_FROMDATE]),
	SELECTEDVALUE( TT_EMP_BOOK[TT_TODATE]),
	Day(
)

 

 

I've also tried looking on the DAX pages provided by microsoft temselves to see what syntax I might be putting down wrong but can't seem to figure it out its all still quite new to me. 

In the end what I hope to achieve is calculating the following and putting it in a new column
Days between 01/01/2023 - 03/01/2023 = 3 * hours per day 8 = 24 hours in total 

Morth_1-1681981207782.png


hopefully someone can lend me a hand and if so thank you in advance.

Edit note: I am using DAX studio 3.0.7 to build my DAX code before using it

1 ACCEPTED SOLUTION
Anonymous
Not applicable

This is because we are using the min value from the whole table, so this hasn't worked. Apologies. Here's a revised idea to get this to work:

 

 

daysOff =

DATEDIFF(
	 TT_EMP_BOOK[TT_FROMDATE],
	 TT_EMP_BOOK[TT_TODATE],
	Day
)

 

 

This is your days between calculated column.

1. Create new column again

2. Enter this code in the column:
answer = ProductX('table', daysOff * hrsperday)

 

let me know, sorry for all the confusion, i think i overcomplicated this.

 

Edit: to correct code

View solution in original post

23 REPLIES 23
Anonymous
Not applicable

I'm experiencing an issue where It doesn't want to recognise the column names with the code it seems to find the table quite alright but not the columns I made sure that they are are typed correct and everything.

Anonymous
Not applicable

Measure 1: Days off = DATEDIFF('table'[start date], 'table'[end date], DAY)

Measure 2: hoursperday = SUM('table'[hoursperday]

Measure 3: [days off] * hoursperday

 

Could potentially be a solution, but still send your code so i can have a look 🙂

Anonymous
Not applicable

Morth_1-1681995301123.png

Here it is! also the error states it cannot get a single value I did try to look into this but I dont need all the rows to be summed together as they all have different values that should be displayed. I wasn't sure of how to do that however I hope this helps you understand the issue 🙂 thanks in advance!

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.