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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
jorgeslzr
Frequent Visitor

Filtering edit query

Hi, I have a data source that has a column with Store_ID, Date, and Status:

STORE_IDDATESTATUS
A101/01Not activated
A101/01Activated
B101/01Activated
C201/02Not Activated

 

As you can see, there can be two status for the same STORE_ID in the same DATE... Since for my measures I do DISTINCTCOUNT on stores, it is useless for me to load row1 (A1 - Not Activated) into my .pbix because I also have it Activated that day. BUT if it is only Not Activated that day (last row for example), I want to keep it in my table.

 

Is there a way I can filter this table in POWER QUERY EDITOR so my .pbix data is much smaller and make it quicker? I want to do this because my data is huge and I could filter that.

 

Thank you!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @jorgeslzr ,

You can edit the applied codes in Advanced Editor to achieve it:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjRU0lEyMjAy0DfUBzH98ksUEpNLMssSS1JTlGJ1MFU4osg64ZV1NkLIGmGaHgsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [STORE_ID = _t, DATE = _t, STATUS = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"STORE_ID", type text}, {"DATE", type date}, {"STATUS", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"DATE", "STORE_ID"}, {{"Count", each Table.RowCount(Table.Distinct(_)), Int64.Type}, {"Details", each _, type table [STORE_ID=nullable text, DATE=nullable date, STATUS=nullable text]}}),
    #"Expanded Details" = Table.ExpandTableColumn(#"Grouped Rows", "Details", {"STATUS"}, {"Details.STATUS"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Details", each ([Details.STATUS] = "Not activated") and ([Count] = 1))
in
    #"Filtered Rows"

advanced editor.JPG

You can also refer the following blog to achieve it:

Grouping in Power Query; Getting The Last Item in Each Group

Best Regards

Rena

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @jorgeslzr ,

You can edit the applied codes in Advanced Editor to achieve it:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjRU0lEyMjAy0DfUBzH98ksUEpNLMssSS1JTlGJ1MFU4osg64ZV1NkLIGmGaHgsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [STORE_ID = _t, DATE = _t, STATUS = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"STORE_ID", type text}, {"DATE", type date}, {"STATUS", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"DATE", "STORE_ID"}, {{"Count", each Table.RowCount(Table.Distinct(_)), Int64.Type}, {"Details", each _, type table [STORE_ID=nullable text, DATE=nullable date, STATUS=nullable text]}}),
    #"Expanded Details" = Table.ExpandTableColumn(#"Grouped Rows", "Details", {"STATUS"}, {"Details.STATUS"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Details", each ([Details.STATUS] = "Not activated") and ([Count] = 1))
in
    #"Filtered Rows"

advanced editor.JPG

You can also refer the following blog to achieve it:

Grouping in Power Query; Getting The Last Item in Each Group

Best Regards

Rena

themistoklis
Community Champion
Community Champion

@jorgeslzr 

 

Based on the description that you sent I suppose you always get the last status based on date field (which must have time as well).

 

In power query you should do some ranking and then select the latest values.

 

You can see the following 2 links:

https://blog.crossjoin.co.uk/2015/05/11/nested-calculations-in-power-query/

https://www.excelguru.ca/blog/2018/06/14/ranking-method-choices-in-power-query/

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.