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
Anonymous
Not applicable

Sum of Measure by Month

Hi, I have data that looks like this (basically door access log):

AccessLog

Date| Time | Event | User

1 Jan | 0400 | Access Logged | Jane

1 Jan | 0600 | Access Logged | Jane

1 Jan | 0700 | Access Logged | Jane

1 Jan | 0200 | Access Logged | Bob

1 Jan | 0800 | Access Logged | Bob

1 Jan | 1200 | Access Logged | Bob

2 Jan | 0400 | Access Logged | Jane

2 Jan | 0600 | Access Logged | Jane

2 Jan | 0700 | Access Logged | Jane

2 Jan | 0200 | Access Logged | Bob

2 Jan | 0800 | Access Logged | Bob

2 Jan | 1200 | Access Logged | Bob

 

I am able to get the hours spend in office each day using:

Hours Worked = (DATEDIFF(FIRSTNONBLANK(AccessLog[Time],1),LASTNONBLANK(AccessLog[Time],1),MINUTE))/60

within a Matrix report with Row = Date, Column = User, Value = Hours Worked

 

Now, I need to calculate the hours work per user, per month.

How can I sum the above 'Hours Worked' measure, by month for each user?

1 ACCEPTED SOLUTION
v-yuta-msft
Community Support
Community Support

Hi powerbi9191,

 

To achieve your requirement, you can create a measure using dax formula below:

Diff = CALCULATE((MAX(AccessLog[Time]) - MIN(AccessLog[Time])) / 60, ALLEXCEPT(AccessLog, AccessLog[Date], AccessLog[User]))

Capture.PNG 

 

Regards,

Jimmy Tao

View solution in original post

2 REPLIES 2
v-yuta-msft
Community Support
Community Support

Hi powerbi9191,

 

To achieve your requirement, you can create a measure using dax formula below:

Diff = CALCULATE((MAX(AccessLog[Time]) - MIN(AccessLog[Time])) / 60, ALLEXCEPT(AccessLog, AccessLog[Date], AccessLog[User]))

Capture.PNG 

 

Regards,

Jimmy Tao

Greg_Deckler
Super User
Super User

Create a Month column using something like:

 

Month = RIGHT([Date],3)

If it is an actual Date/Time column:

 

Month = FORMAT([Date],"mmm")

You will also need a MonthSort column most likely. If it is a date/time column:

 

MonthSort = MONTH([Date])

If it is a text column, then you will need a Switch statement most likely.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.