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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
ratercero
Helper III
Helper III

Sort and Filter Append Query

Hello,

 

The Task is to append 3 queries, filter [Area Responsable]= "Tintoreria" and [Disposición] <> "Aprobado",  after this if duplicate "Lote" leave earliest result ( no duplicates)

I have been able to append the queries: 

let
    Source = Table.Combine({PNC_TELA, PNC_PARTES_CORTADAS, TONO_MALO}),
    #"Removed Other Columns" = Table.SelectColumns(Source,{"Fecha de Ingreso", "Lote", "Defecto 1", "Disposición", "Proceso Responsable"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Other Columns",{{"Fecha de Ingreso", type date}})
in
    #"Changed Type"

 

 

One more question, Can I add a column to wach row telling me from which Database that line is from?

 

Thank you

1 ACCEPTED SOLUTION

You can sort on date and than remove duplicates as illustrated in this short video.

Specializing in Power Query Formula Language (M)

View solution in original post

8 REPLIES 8
Eric_Zhang
Microsoft Employee
Microsoft Employee


@ratercero wrote:

Hello,

 

The Task is to append 3 queries, filter [Area Responsable]= "Tintoreria" and [Disposición] <> "Aprobado",  after this if duplicate "Lote" leave earliest result ( no duplicates)

I have been able to append the queries: 

let
    Source = Table.Combine({PNC_TELA, PNC_PARTES_CORTADAS, TONO_MALO}),
    #"Removed Other Columns" = Table.SelectColumns(Source,{"Fecha de Ingreso", "Lote", "Defecto 1", "Disposición", "Proceso Responsable"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Other Columns",{{"Fecha de Ingreso", type date}})
in
    #"Changed Type"

 

 

One more question, Can I add a column to wach row telling me from which Database that line is from?

 

Thank you


@ratercero

For the last question, you can add a column valuing the database name in each table before combining them.

For the first question, could you please post some sample data for the 3 tables and expected output?

Hello @Eric_Zhang,

 

Sorry for the late response, here it is:

 

Capture.JPG

 

RT

 

 

 

Any ideas anyone else?

@ratercero: the question was already answered by @Eric_Zhang:

"For the last question, you can add a column valuing the database name in each table before combining them."

 

Translated into code, e.g.:

 

let
    Source1 = Table.AddColumn(PNC_TELA, "Source", each "PNC_TELA"),
    Source2 = Table.AddColumn(PNC_PARTES_CORTADAS, "Source", each "PNC_PARTES_CORTADAS"),
    Source3 = Table.AddColumn(TONO_MALO, "Source", each "TONO_MALO"),
    Source = Table.Combine({Source1, Source2, Source3}),
    #"Removed Other Columns" = Table.SelectColumns(Source,{"Fecha de Ingreso", "Lote", "Defecto 1", "Disposición", "Proceso Responsable", "Source"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Other Columns",{{"Fecha de Ingreso", type date}})
in
    #"Changed Type"

 

Specializing in Power Query Formula Language (M)

Hello @MarcelBeug,

 

I used @Eric_Zhang recomendation and this is my code:

 

 

let
    Source1 = Table.AddColumn(PNC_TELA, "Source", each "PNC_TELA"),
    Source2 = Table.AddColumn(PNC_PARTES_CORTADAS, "Source", each "PNC_PARTES_CORTADAS"),
    Source3 = Table.AddColumn(TONO_MALO, "Source", each "TONO_MALO"),
    Source = Table.Combine({Source1, Source2, Source3}),
    #"Removed Other Columns" = Table.SelectColumns(Source,{"Fecha de Ingreso", "Lote", "Defecto 1", "Disposición", "Proceso Responsable", "Source"}),
    #"ChangedType" = Table.TransformColumnTypes(#"Removed Other Columns",{{"Fecha de Ingreso", type date}}),
    #"Filtered Table" =Table.SelectRows(ChangedType, each [Proceso Responsable] = "Tintoreria" and [Disposición]<>"Aprobado" )
in
    #"Filtered Table"


It partially works for my final objective since I need to only the first time a batch # shows and

[Proceso Responsable] = "Tintoreria" and [Disposición]<>"Aprobado"

 , if it repeats with another defects the current code is leaving that entry too.

 

 

 

You can sort on date and than remove duplicates as illustrated in this short video.

Specializing in Power Query Formula Language (M)

@MarcelBeug , will I have to do this everytime I do the refresh? 

No: just add these steps to your query, so it will be part of the refresh.

Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors