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
Anonymous
Not applicable

filter the final output based on column_ mquery

hello, 

 

i have below condition to implemnt in power query, 

 

if source column contain source 1, final output should only have source 1,else source 2. cant be both.

idvar1var2var3Source
1101215source 1
2141414source 2
3111511source 2
4111815source 1
5111012source 1
6202015source 2
7131212source 2
8161516source 1
9111213source 1
10121913source 1

 

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @Anonymous 

Paste this M code in a blank query to see the steps:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI0ABFGIMIUSBTnlxYlpyoYKsXqRCuBRU1QCKi8EVjeGCRqCNMKZqHIm8DlLbCaD9eFcASKvBlQwMgARiDrh5hvDhI1hrvfCF0ebKsZ3H1m6OZbwu03gpmEIo8UNpaYCmIB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [id = _t, var1 = _t, var2 = _t, var3 = _t, Source = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"id", Int64.Type}, {"var1", Int64.Type}, {"var2", Int64.Type}, {"var3", Int64.Type}, {"Source", type text}}),
    hasSource1 = List.Contains(#"Changed Type"[Source], "source 1"),
    res = Table.SelectRows(#"Changed Type", each if hasSource1 then [Source]="source 1"  else [Source]="source 2")
in
    res

 Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

View solution in original post

1 REPLY 1
AlB
Community Champion
Community Champion

Hi @Anonymous 

Paste this M code in a blank query to see the steps:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI0ABFGIMIUSBTnlxYlpyoYKsXqRCuBRU1QCKi8EVjeGCRqCNMKZqHIm8DlLbCaD9eFcASKvBlQwMgARiDrh5hvDhI1hrvfCF0ebKsZ3H1m6OZbwu03gpmEIo8UNpaYCmIB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [id = _t, var1 = _t, var2 = _t, var3 = _t, Source = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"id", Int64.Type}, {"var1", Int64.Type}, {"var2", Int64.Type}, {"var3", Int64.Type}, {"Source", type text}}),
    hasSource1 = List.Contains(#"Changed Type"[Source], "source 1"),
    res = Table.SelectRows(#"Changed Type", each if hasSource1 then [Source]="source 1"  else [Source]="source 2")
in
    res

 Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

Helpful resources

Announcements
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!

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.