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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
lravikiran
Helper I
Helper I

Dynamic data filtering basing condition

Hi guys,

 

      Data Capture issue.PNG

 

I have data that comes that gets added in this format mainly : Year and Category.

 

What I want is to to filter out data basing the field Category ="Act" , so that is suppose if any Year has got a Category = ACT it must filter out the rest .

 

For example , Year = 2017 has ACT,BUD in Category , so the output after filteration or formula must be only 2017 ACT and not 2017 Bud.

 

I really appreciate if the solution in given in the query editor or also dax.

 

I cannot do a manual approach since users keep adding data .

 

@BhaveshPatel 

Regards,

Ravi

 

PBIX

1 ACCEPTED SOLUTION
RolandsP
Resolver IV
Resolver IV

Hi,

 

Here is one way how to solve it in Query Editor.

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwNFPSUQpyU4rVgfMcnUNgXHNMrlNpCoxrgSpriWKSJUxtLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Year = _t, Category = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"Category", type text}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Year"}, #"Changed Type", {"Year"}, "Changed Type", JoinKind.LeftOuter),
    #"Added Custom" = Table.AddColumn(#"Merged Queries", "Custom", each Table.Column([Changed Type], "Category")),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), " "), type text}),
    #"Removed Columns" = Table.RemoveColumns(#"Extracted Values",{"Changed Type"}),
    #"Added Custom1" = Table.AddColumn(#"Removed Columns", "ContainsACT", each if Text.Contains([Custom], "ACT") then 1 else 0),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "FilterColumn", each if [Category] <> "ACT" and [ContainsACT] = 1 then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom2", each ([FilterColumn] = 0)),
    #"Removed Columns1" = Table.RemoveColumns(#"Filtered Rows",{"Custom", "ContainsACT", "FilterColumn"})
in
    #"Removed Columns1"

 

 

View solution in original post

1 REPLY 1
RolandsP
Resolver IV
Resolver IV

Hi,

 

Here is one way how to solve it in Query Editor.

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwNFPSUQpyU4rVgfMcnUNgXHNMrlNpCoxrgSpriWKSJUxtLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Year = _t, Category = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"Category", type text}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Year"}, #"Changed Type", {"Year"}, "Changed Type", JoinKind.LeftOuter),
    #"Added Custom" = Table.AddColumn(#"Merged Queries", "Custom", each Table.Column([Changed Type], "Category")),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), " "), type text}),
    #"Removed Columns" = Table.RemoveColumns(#"Extracted Values",{"Changed Type"}),
    #"Added Custom1" = Table.AddColumn(#"Removed Columns", "ContainsACT", each if Text.Contains([Custom], "ACT") then 1 else 0),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "FilterColumn", each if [Category] <> "ACT" and [ContainsACT] = 1 then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom2", each ([FilterColumn] = 0)),
    #"Removed Columns1" = Table.RemoveColumns(#"Filtered Rows",{"Custom", "ContainsACT", "FilterColumn"})
in
    #"Removed Columns1"

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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