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
uif19085
Helper III
Helper III

DAX measure with 3 layers of intersection

I am facing the following challenge in DAX, I created some mock tables to help illustrate.

IDUniqueIDTestResultS_ReqM_ReqE_ReqTestR_Req
1AA 10000
2BBFailed00010
3CC 01000
4DDPassed00010
5EE 10000
6FFPassed00010
7GG 10000
8HHNot Done00010
9II 00100
10JJFailed00010
11KK 01000
12LLPassed00010
13MM 10000
14NN 00001

 

IDLinkedID
1II
1CC
3HH
3BB
5CC
7KK
9FF
9BB
11HH
11LL
13NN


The second table acts as a "dictionary" that connects rows from Table 1 to other rows from Table 1.
For example:
- ID 1 can be found twice in table 2. Once linked with "II" and a second time linked with "CC".
This means that ID 1 from the first table is asociated with IDs 9 and 3, respectively.
- Next, values "CC" and "II" are themselves connected (based on Table 2 data) to "JJ", "HH" and "FF","BB".
These four can be found back in Table 1 as "test rows" as they have a "TestResult" value associated with each (and a 1/0 value for the Test column).

I am looking for a formula/measure that will count how many S_req rows have at least 1 "Passed" test case connected to it (based on the connections described in Table 2) as well as no "Failed" test cases connected to it, also only E_Req and M_Req will have links to Test. I do have a measure for the first layer of links that checks how many S_Req have at least one link with E_Req or M_Req: 

 
Number of Linked S_Req =
VAR a =
    CALCULATETABLE (
        VALUES ( Table1[ID] ),
        FILTER ( Table1, Table1[S_Req] = 1 )
    )
VAR b =
    CALCULATETABLE (
        VALUES ( Table1[UniqueId] ),
        FILTER ( Table1[E_Req] = 1 || [M_Req] = 1)
    )
VAR c =
    CALCULATETABLE (
        VALUES ( Table2[ID] ),
        FILTER ( Table2,[LinkedID] IN b)
    )
VAR d =
    INTERSECT (c, a)
RETURN
    COUNTX ( d[ID] )


EXAMPLE CALCULATION: - For row ID=1 (AA), we can use Table 2 to conclude that "AA" is connected to "II" and "CC". - Then, by using Table 2 again, we conclude that "II" and "CC" are connected (as a second layer) to "BB", "FF", "HH", and "LL" - For rows "BB", "FF", "HH" and "LL" the values for "TestResult" contain no "Failed" values and at least one "Passed".
- The result for this is 0, because "BB" is unfortunately a failed test.

CALCULATION 2: For row ID=5(EE) by the same logic the result will be 0 beacause will have a failed test.

EXAMPLE CALCULATION 3: - For row ID=7 (GG), we can use Table 2 to conclude that "GG" is connected to  "KK". - Then, by using Table 2 again, we conclude that "KK" is connected (as a second layer) to "HH" and "LL" - For rows "HH" and "LL" the values for "test Result" contain no "Failed" values and at least one "Passed" - The result for this is 1, because there is a "Passed" test and none failed.
Row 13/MM is having a link with an R_Req which it doesn't have an Test link, only E_Req and M_Req have Test links
So the final result will be the sum of all these 3 calculation, so the result is 1.

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Row 13/MM is having a link with an R_Req which it doesn't have an Test link, only E_Req and M_Req have Test links
So the final result will be the sum of all these 3 calculation, so the result is 1.

You lost me at "doesn't have a Test link".

 

For the rest my previous approach still seems to work.

lbendlin_0-1679405784846.png

 

View solution in original post

6 REPLIES 6
lbendlin
Super User
Super User

Row 13/MM is having a link with an R_Req which it doesn't have an Test link, only E_Req and M_Req have Test links
So the final result will be the sum of all these 3 calculation, so the result is 1.

You lost me at "doesn't have a Test link".

 

For the rest my previous approach still seems to work.

lbendlin_0-1679405784846.png

 

I've put that extra column beacause in my data i do have some other calculated columns, an S_Req can have other links too and those links have no Test links. Shouldn't be added a filter? Also you used a Calculated Column, can't this be done by a measure?

The question has to be the other way around: "Does this require a measure or can it be done by a calculated column?"

 

In your case I don't see how user interaction could impact the result. Hence a measure is not required.

You're right. Thank you.  Shouldn't be added some filter for each layer, a filter for the rows where we find an S_Req, a filter for the M_Req or E_Req?

Maybe?  I am not following your logic anymore but feel free to modify the code that I posted.

Well, sir. Thank you for your time. i just added an simple filter and it works. 

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.