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

filter rows by using the "AND" Operator

Hello Community,

 

I have this table 

malekzouaridk_0-1641577043167.png

I want to filters my rows using the AND operator, for example if I select Manufacturing And Quality, it will show me the name of Malek.

I tried changed the OR by AND in the bar formulabut it doesn't work 

malekzouaridk_1-1641577350121.png

malekzouaridk_2-1641577371100.png

 

Thanks in advance

 

 

 

 

1 ACCEPTED SOLUTION
smpa01
Super User
Super User

@Anonymous  I am guessing you want this in PQ. 

 

 

 

Table.SelectRows(
    #"Changed Type",
    each List.Contains(
      List.Intersect(
        {
          List.Distinct(Table.SelectRows(#"Changed Type", each ([entity] = "manufacturing"))[name]),
          List.Distinct(Table.SelectRows(#"Changed Type", each ([entity] = "quality"))[name])
        }
      ),
      [name]
    )
  )

 

 

 

the full code

 

 

 

let
  Source = Table.FromRows(
    Json.Document(
      Binary.Decompress(
        Binary.FromText(
          "i45Wyk3MSc1W0gHSeaVpicklpUWZeelKsToImcLSxJzMkkqwWAVWlYlYRZOw6IXzYwE=",
          BinaryEncoding.Base64
        ),
        Compression.Deflate
      )
    ),
    let
      _t = ((type nullable text) meta [Serialized.Text = true])
    in
      type table [name = _t, entity = _t]
  ),
  #"Changed Type" = Table.TransformColumnTypes(Source, {{"name", type text}, {"entity", type text}}),
  #"Filtered Rows" = Table.SelectRows(
    #"Changed Type",
    each List.Contains(
      List.Intersect(
        {
          List.Distinct(Table.SelectRows(#"Changed Type", each ([entity] = "manufacturing"))[name]),
          List.Distinct(Table.SelectRows(#"Changed Type", each ([entity] = "quality"))[name])
        }
      ),
      [name]
    )
  )
in
  #"Filtered Rows"

 

 

 

DAX would be more performant for a large table

 

 

 

Table =
VAR _base = { "manufacturing", "quality" }
VAR _count =
    COUNTX ( _base, [Value] )
RETURN
    FILTER (
        tbl,
        tbl[entity]
            IN _base
                && CALCULATE ( DISTINCTCOUNT ( tbl[entity] ), ALLEXCEPT ( tbl, tbl[name] ) ) = _count
    )

 

 

 

from

smpa01_0-1641579135832.png

to

 

smpa01_0-1641580740696.png

 

 

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

2 REPLIES 2
smpa01
Super User
Super User

@Anonymous  I am guessing you want this in PQ. 

 

 

 

Table.SelectRows(
    #"Changed Type",
    each List.Contains(
      List.Intersect(
        {
          List.Distinct(Table.SelectRows(#"Changed Type", each ([entity] = "manufacturing"))[name]),
          List.Distinct(Table.SelectRows(#"Changed Type", each ([entity] = "quality"))[name])
        }
      ),
      [name]
    )
  )

 

 

 

the full code

 

 

 

let
  Source = Table.FromRows(
    Json.Document(
      Binary.Decompress(
        Binary.FromText(
          "i45Wyk3MSc1W0gHSeaVpicklpUWZeelKsToImcLSxJzMkkqwWAVWlYlYRZOw6IXzYwE=",
          BinaryEncoding.Base64
        ),
        Compression.Deflate
      )
    ),
    let
      _t = ((type nullable text) meta [Serialized.Text = true])
    in
      type table [name = _t, entity = _t]
  ),
  #"Changed Type" = Table.TransformColumnTypes(Source, {{"name", type text}, {"entity", type text}}),
  #"Filtered Rows" = Table.SelectRows(
    #"Changed Type",
    each List.Contains(
      List.Intersect(
        {
          List.Distinct(Table.SelectRows(#"Changed Type", each ([entity] = "manufacturing"))[name]),
          List.Distinct(Table.SelectRows(#"Changed Type", each ([entity] = "quality"))[name])
        }
      ),
      [name]
    )
  )
in
  #"Filtered Rows"

 

 

 

DAX would be more performant for a large table

 

 

 

Table =
VAR _base = { "manufacturing", "quality" }
VAR _count =
    COUNTX ( _base, [Value] )
RETURN
    FILTER (
        tbl,
        tbl[entity]
            IN _base
                && CALCULATE ( DISTINCTCOUNT ( tbl[entity] ), ALLEXCEPT ( tbl, tbl[name] ) ) = _count
    )

 

 

 

from

smpa01_0-1641579135832.png

to

 

smpa01_0-1641580740696.png

 

 

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Pragati11
Super User
Super User

Hi @Anonymous ,

 

I think you will need to use List.Contains in M code. Somthing like below:

= Table.SelectRows(#"Renamed Columns", each List.Contains({'Manufacturing', 'Quality'}, [Entity]))

Just make sure to check column name, all argumets and column values in above code.

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

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.