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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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