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

Remove rows for last 3 weeks - power query

I have a query with several columns and want to filter it dynamicly removing last 3  "Week id" from a column.

Product Week id

X               1

Y               1

Z               2

X               4

Z               4

Z               5

Y               7

 

The output should look like this:

Product Week id

X               1

Y               1

Z               2

X               4

Z               4

 

Weeks, 7,6,5 was removed. Although there was no data for week id = 6 it should be counted.

I would have this in PQ.

Thanks in advance

 

1 ACCEPTED SOLUTION
Stachu
Community Champion
Community Champion

try this code

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WilDSUTJUitWJVoqEs6KALCMwCyRrAhdDsEzhOsyVYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Tab = _t, WeekId = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Tab", type text}, {"WeekId", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each [WeekId] < List.Max(#"Changed Type"[WeekId])-2)
in
    #"Filtered Rows"

for your application you should use the last line and replace the blue parts with names specific to your setup



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

View solution in original post

2 REPLIES 2
Stachu
Community Champion
Community Champion

try this code

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WilDSUTJUitWJVoqEs6KALCMwCyRrAhdDsEzhOsyVYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Tab = _t, WeekId = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Tab", type text}, {"WeekId", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each [WeekId] < List.Max(#"Changed Type"[WeekId])-2)
in
    #"Filtered Rows"

for your application you should use the last line and replace the blue parts with names specific to your setup



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Anonymous
Not applicable

Thanks for clear answer. Works Great!

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.