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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Giovani
Helper I
Helper I

Dynamic filter based in multiple columns and criteria

I am struggling with something that may be simple to solve. By year and month, I want to make a dynamic bar chart to present counts by a distinct ID that fits criteria based on columns Filter1 and Filter2. For simplicity, I am only using as an example a few lines from a large table, assuming all are from the same year and month.

ID

Filter1

Filter2

ID1

A

D

ID1

B

D

ID2

A

F

ID2

B

E

ID3

A

D

ID3

B

F

ID4

B

D

ID4

C

D

ID5

B

D

ID5

C

E

ID6

A

D

ID6

B

D

ID6

C

D

 

An example of questions I am trying to answer and visualize are

1-How many times A and B were concomitantly present in an ID? Answer = 4 (ID1;ID2;ID3;ID6). This would later be used to answer a similar question applied to B and C, or for the three of them A, B, and C.

2- How many times A and B were concomitantly present in an ID, and A had Filter2= D and B had Filter2=  D?

Answer= 2 (ID1; ID6)

2- How many times A and B were concomitantly present in an ID, and A had Filter2=  D and B had Filter2=  E?

Answer= 0

 

Any help in how I could do this is welcome!

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

@Giovani might these code help

 

 

ID_Count:=COUNTROWS (
    FILTER (
        VALUES ( SampleData[ID] ),
        VAR _Filter1 =
            CALCULATETABLE (
                VALUES ( SampleData[Filter1] ),
                ALLEXCEPT ( SampleData, SampleData[ID] )
            )
        RETURN
            AND ( CONTAINSROW ( _Filter1, "A" ), CONTAINSROW ( _Filter1, "B" ) )
    )
)
----------------------------
ID_Count2:=COUNTROWS (
    FILTER (
        VALUES ( SampleData[ID] ),
        VAR _Filter1 =
            CALCULATETABLE (
                SUMMARIZE ( SampleData, SampleData[Filter1], SampleData[Filter2] ),
                ALLEXCEPT ( SampleData, SampleData[ID] )
            )
        RETURN
            AND ( CONTAINSROW ( _Filter1, "A", "D" ), CONTAINSROW ( _Filter1, "B", "D" ) )
    )
)
----------------------
ID_Count3:=COUNTROWS (
    FILTER (
        VALUES ( SampleData[ID] ),
        VAR _Filter1 =
            CALCULATETABLE (
                SUMMARIZE ( SampleData, SampleData[Filter1], SampleData[Filter2] ),
                ALLEXCEPT ( SampleData, SampleData[ID] )
            )
        RETURN
            AND ( CONTAINSROW ( _Filter1, "A", "D" ), CONTAINSROW ( _Filter1, "B", "E" ) )
    )
)

 

wdx223_Daniel_0-1603939991712.png

 

 

View solution in original post

2 REPLIES 2
wdx223_Daniel
Super User
Super User

@Giovani might these code help

 

 

ID_Count:=COUNTROWS (
    FILTER (
        VALUES ( SampleData[ID] ),
        VAR _Filter1 =
            CALCULATETABLE (
                VALUES ( SampleData[Filter1] ),
                ALLEXCEPT ( SampleData, SampleData[ID] )
            )
        RETURN
            AND ( CONTAINSROW ( _Filter1, "A" ), CONTAINSROW ( _Filter1, "B" ) )
    )
)
----------------------------
ID_Count2:=COUNTROWS (
    FILTER (
        VALUES ( SampleData[ID] ),
        VAR _Filter1 =
            CALCULATETABLE (
                SUMMARIZE ( SampleData, SampleData[Filter1], SampleData[Filter2] ),
                ALLEXCEPT ( SampleData, SampleData[ID] )
            )
        RETURN
            AND ( CONTAINSROW ( _Filter1, "A", "D" ), CONTAINSROW ( _Filter1, "B", "D" ) )
    )
)
----------------------
ID_Count3:=COUNTROWS (
    FILTER (
        VALUES ( SampleData[ID] ),
        VAR _Filter1 =
            CALCULATETABLE (
                SUMMARIZE ( SampleData, SampleData[Filter1], SampleData[Filter2] ),
                ALLEXCEPT ( SampleData, SampleData[ID] )
            )
        RETURN
            AND ( CONTAINSROW ( _Filter1, "A", "D" ), CONTAINSROW ( _Filter1, "B", "E" ) )
    )
)

 

wdx223_Daniel_0-1603939991712.png

 

 

Many thanks to @wdx223_Daniel this is perfect and is exactlly what I was looking for!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.