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
Giovani
Helper I
Helper I

Dynamic filter bases on two columns

I am struggling with something that may be simple to solve. I want to make a dynamic bar chart, by year and month, to present counts of distinct ID that fits the 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 the questions I am trying to visualize is?

1-How many times A and B were concomitantly present in an ID? Answer = 4 (ID1;ID2;ID3;ID6). This would later answer a similar question to B and C, or for the three 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!

 

2 REPLIES 2
amitchandak
Super User
Super User

@Giovani , First 2 should be possible using

measure =
var _cnt = countrows(selectedvalues(Table[Filter1]))
return
countx(filter(summarize(table,Table[ID],"_1" ,calculate(distinctCOUNT(Table[ID]))),[_1]=_cnt),[_1])

 

Last on can not be dynamic unless you can cat two fields or try like


measure =
var _cnt = countrows(selectedvalues(Table[Filter1]))
return
countx(filter(summarize(table,Table[ID],"_1" ,calculate(distinctCOUNT(Table[ID]), filter(Table, (Table[Filter1] ="A" && Table[Filter2] ="D") || (Table[Filter1] ="B" && Table[Filter2] ="E" )))),[_1]=_cnt),[_1])

@amitchandak  Thanks for the help. But I couldn`t make it work.

Syntax error:

The syntax for 'Table' is incorrect. (DAX(var _cnt = countrows(selectedvalue(Table[Filter1]))returncountx(filter(summarize(table,Table[ID],"_1" ,calculate(distinctCOUNT(Table[ID]))),[_1]=_cnt),[_1]))).

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.