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
cosminc
Post Partisan
Post Partisan

DAX with 2 Table Filters and result the common ID

Hi all,

I'm stucked with this:

 

YearMonthIDLabelValueClient
201811A1cosmin
201811B1cosmin
201811C1cosmin
201812A0cosmin
201812B1cosmin
201812C1cosmin
201813A0cosmin
201813B1cosmin
201813C0cosmin
201814A1cosmin
201814B1cosmin
201814C0cosmin
201825A1cosmin
201825B0cosmin
201825C99cosmin
201821A1marius
201821B0marius
201821C1marius
201822A0marius
201822B1marius
201822C1marius
201823A0marius
201833B1marius
201833C0marius
201834A1marius
201834B0marius
201834C1marius
201835A0marius
201835B1marius
201835C0marius

 

 

i need to obtain 2 ID list on tables variable and after that i need to count how many are common

when apply slicers on year, month, client i need to adjust after them

something like this:

 

count_measure = 

VAR tabel_filter_A =
CALCULATETABLE( VALUES( Source[ID] ),FILTER(Source, Source[Value] = 1 && Source[Label] = "A"))
VAR tabel_filter_B =
CALCULATETABLE( VALUES( Source[ID] ),FILTER(Source, Source[Value] = 1 && Source[Label] = "B"))
VAR result = CALCULATE ( COUNT (Source[Value]) , FILTER(Source, Source[ID] IN table_filter_A && Source[ID] IN table_filter_B))
RETURN
result

 

can you help me please with the right syntax?

Cosmin

 

1 ACCEPTED SOLUTION
MitchM
Resolver II
Resolver II

I would be happy to give it a go. It would help to know what you would expect the result to be for the dataset you provided. It looks like you want to count the value rows when the Source ID is in your two variable tables. In the code you show that would mean that you would count the number of rows where the value is 1 and the source is A AND B. In your data set the ID's 1,4,5 appear in both tables, therefore there should be 18 value rows that meet your criteria. This code will return 18:

 

Measure = 
VAR Table_A = 
    CALCULATETABLE( 
        VALUES( Source[ID] ),
        Source[Value] = 1,
        Source[Label] = "A" )
VAR Table_B = 
    CALCULATETABLE(
        VALUES( Source[ID] ),
        Source[Value] = 1,
        Source[Label] = "B" )
RETURN
    CALCULATE(
        COUNT( Source[Value] ),
        Source[ID] IN Table_A &&
        Source[ID] IN Table_B
    )

Hopefully this helps.

View solution in original post

2 REPLIES 2
MitchM
Resolver II
Resolver II

I would be happy to give it a go. It would help to know what you would expect the result to be for the dataset you provided. It looks like you want to count the value rows when the Source ID is in your two variable tables. In the code you show that would mean that you would count the number of rows where the value is 1 and the source is A AND B. In your data set the ID's 1,4,5 appear in both tables, therefore there should be 18 value rows that meet your criteria. This code will return 18:

 

Measure = 
VAR Table_A = 
    CALCULATETABLE( 
        VALUES( Source[ID] ),
        Source[Value] = 1,
        Source[Label] = "A" )
VAR Table_B = 
    CALCULATETABLE(
        VALUES( Source[ID] ),
        Source[Value] = 1,
        Source[Label] = "B" )
RETURN
    CALCULATE(
        COUNT( Source[Value] ),
        Source[ID] IN Table_A &&
        Source[ID] IN Table_B
    )

Hopefully this helps.

that's it!

so 1, 4 & 5 are common ID

the expected result is 3

my mistake that in the example for each label the id is not unique; in the real base it is and your syntax i divided to the number of table variable (/2 in example)

perfect!

thanks!!

Cosmin

 

 

 

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.