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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Sam_Zeus
Frequent Visitor

Automatically deleting inputted weekly data with Power Query(M) that does not represent a full month

Hey all,

I'm handling some data in a report and I was wondering how to do a computation while importing said data.

The data is split up by "scenarios", which is further split up by weeks (or partial weeks, example: time_bucket_id 1 goes from 28/10-31/10, time_bucket_id 2 goes from 01/11-03/11, filling up the rest of the week under a different time id due to it being a different month) however some scenarios' data starts only partway through the first month, making it look like said first month has super underperformed.

I want to automatically get rid of the incomplete first months with this logic (pseudo code but table names encased in "" are correct):
if( "scenario_id"'s "time_bucket_id" = 1 and day("time_bucket_id"'s "start date") != 1 ), remove( row, and all other rows from the same "scenario_id" on the same month("time_bucket_id"'s "start_date") and year("time_bucket_id"'s "start_date") )
But I'm not entirely sure how to perform it in M, any help would be greatly appreciated.

Small clarifications:
A scenario's first date will always have a time_bucket_id of 1, and is in the space of weeks.
Each time bucket id has a date on which it starts, days of the week are irrelevant I only want to it check for 1st's of said months.
If you need any other clarifications just ask

3 REPLIES 3
v-frfei-msft
Community Support
Community Support

Hi @Sam_Zeus ,

 

In you scenario, Please have a try to use Table.Group .

If it doesn't meet your requirement,  Kindly share your sample data and excepted result to me if you don't have any Confidential Information. Please upload your files to One Drive and share the link here.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

@v-frfei-msft 
From the following code I now have this:
let
Source = Oracle.Database(__),
#"Sorted Rows" = Table.Sort(Source,{{"SCENARIO_ID", Order.Ascending}, {"TIME_BUCKET_ID", Order.Ascending}}),
#"Table Grouping" = Table.Group(#"Sorted Rows", "SCENARIO_ID", {"All rows", each _, type table})
in
#"Table Grouping"
Proof.PNG
How do I:
A: Use the Table.RemoveFirstN inside these new mini tables?
B: Once I'm done with processing the data how to it revert it back to being one table?

Sam_Zeus
Frequent Visitor

I've gotten a little further in fixing it, I trialed a fix on a table with only 1 scenario and it worked:
Source = Oracle.Database(___),
#"Sorted Rows" = Table.Sort(Source,{{"SCENARIO_ID", Order.Ascending}, {"TIME_BUCKET_ID", Order.Ascending}}),
#"Test" = Table.RemoveFirstN(#"Sorted Rows", each Date.Day([START_DATE]) <> 1)

 

However I need to to be able to loop through multiple scenarios, kind of similar to this (code doesnt work but general idea):

Source = Oracle.Database(___),
#"Sorted Rows" = Table.Sort(Source,{{"SCENARIO_ID", Order.Ascending}, {"TIME_BUCKET_ID", Order.Ascending}}),
#"Test" = each [SCENARIO_ID] (Table.RemoveFirstN(#"Sorted Rows", each Date.Day([START_DATE]) <> 1))

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.