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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
wmgemmell
Frequent Visitor

Query all shift data from Teams/Shifts to analyze in Power BI

Greetings, Community.

 

I know this may be a question for another location but I am ultimately working with Power BI so I thought I would try here, too.

 

I am working on trying to query all available shift data from various Teams.  I have been successful with the below but it only provides my personal shift data from a test team I have set up and will not provide the data for the other two test members within that team.  I've tried searching for ways of doing this but haven't found anything useful as of yet.  Any thoughts or points of direction are greatly appreciated.

 

GET https://graph.microsoft.com/v1.0/teams/{TeamID}/schedule/shifts Used beta as well

Permissions:  Group.Read.All & Group.ReadWrite.All\

 

Currently, I am researching the use of Azure AD and the console to call Graphs for this task.  At least it looks like this might be the path that needs followed.  I am reading up on this now but if anyone has any advice or better direction, that, too, is appreciated.

 

Thank you in advance for your help.

 

Wm

1 ACCEPTED SOLUTION
wmgemmell
Frequent Visitor

As an update, I was able to solve this using the Graph Explorer v1.0 with the following ODATA query:

 

= OData.Feed("https://graph.microsoft.com/v1.0/teams/"[Team ID]"/schedule", null, [Implementation="2.0"])

View solution in original post

4 REPLIES 4
wmgemmell
Frequent Visitor

As an update, I was able to solve this using the Graph Explorer v1.0 with the following ODATA query:

 

= OData.Feed("https://graph.microsoft.com/v1.0/teams/"[Team ID]"/schedule", null, [Implementation="2.0"])

v-deddai1-msft
Community Support
Community Support

Hi @wmgemmell ,

 

Would you please refer to the similar post:https://community.powerbi.com/t5/Power-Query/Pull-data-from-a-REST-API-Authentication/td-p/246006?

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

 

Hi, @v-deddai1-msft.

 

Thank you for your reply.  I do not see this as the solution.  I am not having any trouble pulling the data into Power BI, it is more what query is needed in Graphs that will query all Teams members Shifts data.  Right now, my query only provides my personal shift data, not everyone elses.  Pulling the data into Power BI is straight forward though using the ODATA feed.

 

Wm

I was thoroughly helped by this Solution.   When I used the Odata connector as described by v-deddai1-msft, I get all of the shifts. I am an "owner" of the team. Perhaps if you are a "member" you only see your own shifts?   A couple of other things to note:

 

1. to get the GUID for the team, you can use the 'three dot' menus to a. Manage team, then b. Get a link to the team c. get the part of the link after groupid= and before the next ampersand (&)

 

2. The date/time stamps are in UTC time, so you have to adjust to local time to make it useful.

 

3. This will only get you the GUID for each user.  * IF * you have "read ALL" permission to the groups in your org, then you can just tack "/members" after the GroupGUID and run the odata query again (I think??).... however - if you don't - then you can get the data using Power Automate -- one that works is the "List Group Members" connector that is part of the "Office 365 Groups."  In my experience, this works if I am an OWNER of the Group / Team.

 

4. For efficiency's sake - you might take note that you can use ?$filter= to require that the shift is newer than some date or something like that.

 

5. Some of the rows that are returned are of the type "Record" - when that happens, you can click the little button at the top-right of the column in Power Query to SPLIT the record into it's components (and you can choose to select the components you want to keep).

 

6. A shift can have a draft date, but no "shared" date.  OR vice-verse.  OR it can have both - I guess if the draft date is newer, then a request was contemplated but never "Shared" -- I don't know enough about the process.

 

Here's a rudimentary custom function for time zone adjustment. Requires two parameters to be created ("DateTimeToAdjust" and "BaseHoursAdjustmentFromUTC" - and - at this point it requires you to know the timezone offset hours (in my example, the team is all in the same zone).   Make the Params, Make a query using the code below, then right-click and click on Create Function.

 

 

let
    DateInUTC = DateTimeToAdjust,
    DateInTargetZone_PreDST = DateTimeToAdjust + #duration(0, BaseHoursAdjustmentFromUTC ,0,0),
    //DateInTargetZone_PreDST = DateTimeZone.SwitchZone( DateAdjusted, BaseHoursAdjustmentFromUTC, 0), 

    //now prep for DST Adjustment
    Summertime = Date.StartOfWeek( #date(Date.Year(DateTimeToAdjust ),3,14), Day.Sunday),
    Wintertime = Date.StartOfWeek( #date(Date.Year(DateTimeToAdjust ),11,7), Day.Sunday),

    //below just removes the +0, or -4, etc so that we can use comparison operators. It doesn't revert the time to UTC or anything extreme. 
    DateInTargetZone_PreDST2 = DateTimeZone.RemoveZone(DateInTargetZone_PreDST ), 

    DateInTargetZone = if DateInTargetZone_PreDST2 < Summertime & #time(0,0,0) or DateInTargetZone_PreDST2 > Wintertime & #time(0,0,0) 
                            then DateInTargetZone_PreDST2 
                            else DateInTargetZone_PreDST2 + #duration(0,-1 ,0,0)


in
    if DateInUTC <> "" and DateInUTC <> null  then DateInTargetZone else null

 

 

 

Finally - here's my query for preparing the Shifts data - hope it helps you (I expect it will help ME when I next need to do this!)

 

 

let
    Source = OData.Feed("https://graph.microsoft.com/v1.0/teams/" & "e3333333-3333-333-a333-3333ffad3333" & "/schedule", null, [Implementation="2.0"]), //GUID of your team, of course
    shifts = Source[shifts],
    #"Filtered Rows" = Table.SelectRows(shifts, each [userId] <> null and [userId] <> "" and [lastModifiedDateTime] > #datetimezone(2024, 10, 1, 0, 0, 0, -5, 0) ), //I just used a random date as a filter to keep my data size small in testing
    #"Expanded lastModifiedBy" = Table.ExpandRecordColumn(#"Filtered Rows", "lastModifiedBy", {"user"}, {"lastModifiedBy.user"}),
    #"Expanded lastModifiedBy.user" = Table.ExpandRecordColumn(#"Expanded lastModifiedBy", "lastModifiedBy.user", {"displayName", "id"}, {"lastModifiedBy.user.displayName", "lastModifiedBy.user.id"}),
    #"Expanded sharedShift" = Table.ExpandRecordColumn(#"Expanded lastModifiedBy.user", "sharedShift", {"endDateTime", "startDateTime", "theme", "displayName", "notes"}, {"sharedShift.endDateTime", "sharedShift.startDateTime", "sharedShift.theme", "sharedShift.displayName", "sharedShift.notes"}),
    #"Expanded draftShift" = Table.ExpandRecordColumn(#"Expanded sharedShift", "draftShift", {"endDateTime", "startDateTime", "theme", "displayName", "notes"}, {"draftShift.endDateTime", "draftShift.startDateTime", "draftShift.theme", "draftShift.displayName", "draftShift.notes"}),
    AddedLocal_SharedStart = Table.AddColumn(#"Expanded draftShift", "sharedShift.startDateTime_Local", each fnTimeZoneAdjustment(-5, [sharedShift.startDateTime])),
    AddedLocal_SharedEnd = Table.AddColumn(AddedLocal_SharedStart, "sharedShift.endDateTime_Local", each fnTimeZoneAdjustment(-5, [sharedShift.endDateTime])),
    AddedLocal_DraftStart = Table.AddColumn(AddedLocal_SharedEnd, "draftShift.startDateTime_Local", each fnTimeZoneAdjustment(-5, [draftShift.startDateTime])),
    AddedLocal_DraftEnd = Table.AddColumn(AddedLocal_DraftStart, "draftShift.endDateTime_Local", each fnTimeZoneAdjustment(-5, [draftShift.endDateTime])),



    #"Changed Type" = Table.TransformColumnTypes(AddedLocal_DraftEnd,{{"sharedShift.startDateTime_Local", type datetime},{"sharedShift.endDateTime_Local", type datetime},{"draftShift.endDateTime_Local", type datetime},{"draftShift.startDateTime_Local", type datetime}}),
    #"Replaced Errors" = Table.ReplaceErrorValues(#"Changed Type", {{"sharedShift.startDateTime_Local", null},{"sharedShift.endDateTime_Local", null},{"draftShift.startDateTime_Local", null},{"draftShift.endDateTime_Local", null}})
in
    #"Replaced Errors"

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.