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
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
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.