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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
G_Whit-UK
Helper II
Helper II

Power Query Editor - Remove Rows - Conditional

Hi,

 

My data set has a number of transaction references and transaction dates (amoungst other fields).  On the dates when the transaction closes, I get two lines for the same date, due to having different transaction status codes ("Settled" vs "Closed").   When a transaction is still open (in the defined date range), the status code will be relfetced as "Settled".  I'd like to filter the data so that the duplicated dates only reflect the "Closed" line, but still retain the data for the transactions which are still in "Settled" status.  I've attempted the "Group By" tool, but I cannot find a conditional statement to make it select the "Closed" How do I go about getting the required output?

 

Thanks.

 

Here is an example:  I'd like the final version of the data to exclude the two highlighted lines while retaining all the others.

Data ExampleData Example

 

 

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @G_Whit-UK ,

 

In this case you can use the group by option but for the aggregation select the minimum value since you want the closed.

 

Check the code below with an example:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hc89CsAgDAXguzgLJrGJ2dtuQgfdxPtfo7Fbf6Tje3y8kNZcBFaNlJx3uASkQIBsoey15n1z3Q8joqRkNenUJGSAaDVIABxGLKz5KD/kPqOMItepNJv5Jo8ZjSrjKwNAL9NP", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Num = _t, LOAN_STETTLEMENT_DATE = _t, LOAN_STATUS = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Num", Int64.Type}, {"LOAN_STETTLEMENT_DATE", type date}, {"LOAN_STATUS", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Num", "LOAN_STETTLEMENT_DATE"}, {{"LOAN_STATUS", each List.Min([LOAN_STATUS]), type text}})
in
    #"Grouped Rows"

 

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

3 REPLIES 3
MFelix
Super User
Super User

Hi @G_Whit-UK ,

 

In this case you can use the group by option but for the aggregation select the minimum value since you want the closed.

 

Check the code below with an example:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hc89CsAgDAXguzgLJrGJ2dtuQgfdxPtfo7Fbf6Tje3y8kNZcBFaNlJx3uASkQIBsoey15n1z3Q8joqRkNenUJGSAaDVIABxGLKz5KD/kPqOMItepNJv5Jo8ZjSrjKwNAL9NP", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Num = _t, LOAN_STETTLEMENT_DATE = _t, LOAN_STATUS = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Num", Int64.Type}, {"LOAN_STETTLEMENT_DATE", type date}, {"LOAN_STATUS", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Num", "LOAN_STETTLEMENT_DATE"}, {{"LOAN_STATUS", each List.Min([LOAN_STATUS]), type text}})
in
    #"Grouped Rows"

 

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Thanks @MFelix 

 

Rather than work with raw code, I was able to get it to work using the advanced feature within the "Group By" tool - which I found to be a bit easier.

Test OuputTest Ouput

Hi @G_Whit-UK ,

 

The raw code I have send out to you was for you to have the example,  by copy pasting to advance editor you would be abble to see the step by step that I have made. I achieve the result with the same tool as you and not by direct coding.

 

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



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!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.