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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
pallavi_r
Super User
Super User

Sharepoint Recycle Bin as Datasource

Hi All,

 

Can I access the details of sharepoint site - > recycle bin content/list from Power BI.

 

The recycle bin list shows file name and how many days the file will be deleted. I have to capture this in the report.

 

Kindly advise.

 

Thanks,

Pallavi

3 ACCEPTED SOLUTIONS
danextian
Super User
Super User

Hi @pallavi_r 

 

That is currently not possible with Power BI - not with any available SharePoint connectors.  Check this out for the workaround on how to get the data:

https://community.fabric.microsoft.com/t5/Power-Query/Use-SharePoint-Recycle-Bin-as-a-Data-Source/td... 










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

OwenAuger
Super User
Super User

Hi @pallavi_r 

I'm not sure if this meets your requirements, but I was able to query the list of files (but not content of files) in a SharePoint Online site's recycle bin with this:

 

 

let
    SiteURL = "https://YOUR_TENANT.sharepoint.com/sites/YOUR_SITE",
    SharePointRecycleBin = OData.Feed(SiteURL & "/_api/web/RecycleBin")
in
    SharePointRecycleBin

 

 

Appears to refresh successfully in the service with OAuth credentials.


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

Hi @pallavi_r 

Glad that this helped!

I did some testing at my end to locate files in the Second-Stage Recycle Bin (aka Site Collection Recycle Bin).

 

For my test site, it appears that if you use the above query with path

 

"/_api/site/RecycleBin"

 

 and filter on ItemState = 2, this corresponds to the Second-Stage Recycle Bin.

 

So the full query to get Second-Stage Recycle Bin that worked in my case is:

 

let
    SiteURL = "https://YOUR_TENANT.sharepoint.com/sites/YOUR_SITE",
    SharePointRecycleBin = OData.Feed(SiteURL & "/_api/site/RecycleBin"),
    #"ItemState 2" = Table.SelectRows(SharePointRecycleBin, each ([ItemState] = 2))
in
    #"ItemState 2"

 

This worked for me at least. I think technically the Second-Stage Recycle Bin exists per site collection rather than per site (in my case there is one site per collection anyway), so the query may vary when multiple sites are in one collection, but I'm not an expert on this aspect of SharePoint Online myself 😉

 

Does something like this work for you?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

10 REPLIES 10
OwenAuger
Super User
Super User

Hi @pallavi_r 

I'm not sure if this meets your requirements, but I was able to query the list of files (but not content of files) in a SharePoint Online site's recycle bin with this:

 

 

let
    SiteURL = "https://YOUR_TENANT.sharepoint.com/sites/YOUR_SITE",
    SharePointRecycleBin = OData.Feed(SiteURL & "/_api/web/RecycleBin")
in
    SharePointRecycleBin

 

 

Appears to refresh successfully in the service with OAuth credentials.


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Hi @OwenAuger ,

Thanks a lot. It worked finally. I just modified your code from web to site. its working.

let
    SiteURL = "https://YOUR_TENANT.sharepoint.com/sites/YOUR_SITE",
    SharePointRecycleBin = OData.Feed(SiteURL & "/_api/site/RecycleBin")
in
    SharePointRecycleBin

 

Thank you so much. Appreciate a lot. 

Any idea we can get to second stage recycle bin?

 

Thanks,

Pallavi

Hi @pallavi_r 

Glad that this helped!

I did some testing at my end to locate files in the Second-Stage Recycle Bin (aka Site Collection Recycle Bin).

 

For my test site, it appears that if you use the above query with path

 

"/_api/site/RecycleBin"

 

 and filter on ItemState = 2, this corresponds to the Second-Stage Recycle Bin.

 

So the full query to get Second-Stage Recycle Bin that worked in my case is:

 

let
    SiteURL = "https://YOUR_TENANT.sharepoint.com/sites/YOUR_SITE",
    SharePointRecycleBin = OData.Feed(SiteURL & "/_api/site/RecycleBin"),
    #"ItemState 2" = Table.SelectRows(SharePointRecycleBin, each ([ItemState] = 2))
in
    #"ItemState 2"

 

This worked for me at least. I think technically the Second-Stage Recycle Bin exists per site collection rather than per site (in my case there is one site per collection anyway), so the query may vary when multiple sites are in one collection, but I'm not an expert on this aspect of SharePoint Online myself 😉

 

Does something like this work for you?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Hi  @OwenAuger , 

Thank you, that's amazing. You have solved my problem. How did you find this?

Yes with the itemstate = 2 filter, I could get into second stage recycle bin.

One thing I noticed, when I use the below code, I get both first stage and second stage recycle bin.

"/_api/site/RecycleBin"

 So now I can get a list where both first stage and 2nd stage deleted items are there. Did not find any attribute to distinguish.

And I can get the list where second stage deleted items are there.

 

I would also need the deleted items only from first stage recycle bin. How to get that?

 

Thank you so much. Appreciate a lot for this great help. 

 

Thanks,

Pallavi

@OwenAuger

You're welcome @pallavi_r .

To be honest, I found this through trial and error, and piecing together info from some Microsoft documentation pages (e.g. here).

 

Just to clarify, it appears that ItemState represents the "recycle bin stage".

 

So if you just use this query, you can return both 1st and 2nd stage recycle bins and distinguish them with the ItemState column.

At least this is how it appears for my test site:

let
    SiteURL = "https://YOUR_TENANT.sharepoint.com/sites/YOUR_SITE",
    SharePointRecycleBin = OData.Feed(SiteURL & "/_api/site/RecycleBin")
in
    SharePointRecycleBin

OwenAuger_0-1738262218544.png

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Hi @OwenAuger ,

 

Thanks for the documentation link, it is so so helpful, great finding. This itemstate will distinguish and solves the issue. Thank you!

 

Thanks,

Pallavi

Hi @OwenAuger ,

Thanks for you reply. I was trying the steps mentioned above, but I am not getting anything. This is giving some xml which does not have list. Could you please put the step by step snapshot for my reference.

That will be great help.

Thanks,

Pallavi

Hi @OwenAuger ,

Thanks for you reply. I was trying the steps mentioned above, but I am not getting anything. This is giving some xml which does not have list. Could you please put the step by step snapshot for my reference.

That will be great help.

Thanks,

Pallavi

danextian
Super User
Super User

Hi @pallavi_r 

 

That is currently not possible with Power BI - not with any available SharePoint connectors.  Check this out for the workaround on how to get the data:

https://community.fabric.microsoft.com/t5/Power-Query/Use-SharePoint-Recycle-Bin-as-a-Data-Source/td... 










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi @danextian , thanks for confirming the same. 

Thanks,

Pallavi

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.