Forum Discussion

Kruz_R's avatar
Kruz_R
New Member
3 years ago
Solved

Calculated column based on multiple criteria from another table

Hello,

 

I hope someone can assist or point me toward a relevant post.

 

I am struggling to create a calculated column Table 1[READY] that meets criteria from Table 2 [Prof] and [Current] columns. Due to an "Active" relationship between other tables in the data model, an "Inactive Relationship" could be made between the two Employee Columns.

 

What I am hoping to achieve is the result for the Table 1 [READY] column are Prof 1 & 2 & 3 = "Y" && Prof 4 || 5 = "Y" then "Yes", else "No" (or a 1 or 0) which ever is easiest.

 

Table 1

EmployeeReady
1No
2Yes
3No
4Yes
5No
6 
7 

 

TABLE 2

EmployeeProfCurrent
11y
12y
13y
14n
15n
21y
22y
23y
24y
25n
31n
32y
33n
34y
35n
41y
42y
43y
44n
45y
51y
52y
53y
54y
55n
61n
62y
63y
64n
65y
71y
72y
73y
74y
75n

 

Happy for any suggestions and can provide additional information if required.

 

Thanks in advance.

 

Kruz

  • Hi,

    Please check the below picture and the attached pbix file.

    It is for creating a new column.

     

     

    Ready CC =
    VAR _category =
        FILTER ( Table2, Table2[Employee] = EARLIER ( Table1[Employee] ) )
    RETURN
        IF (
            MAXX ( FILTER ( _category, Table2[Prof] = 1 ), Table2[Current] ) = "y"
                && MAXX ( FILTER ( _category, Table2[Prof] = 2 ), Table2[Current] ) = "y"
                && MAXX ( FILTER ( _category, Table2[Prof] = 3 ), Table2[Current] ) = "y"
                && OR (
                    MAXX ( FILTER ( _category, Table2[Prof] = 4 ), Table2[Current] ) = "y",
                    MAXX ( FILTER ( _category, Table2[Prof] = 5 ), Table2[Current] ) = "y"
                ),
            "Yes",
            "No"
        )
    

     

2 Replies

  • Hi,

    Please check the below picture and the attached pbix file.

    It is for creating a new column.

     

     

    Ready CC =
    VAR _category =
        FILTER ( Table2, Table2[Employee] = EARLIER ( Table1[Employee] ) )
    RETURN
        IF (
            MAXX ( FILTER ( _category, Table2[Prof] = 1 ), Table2[Current] ) = "y"
                && MAXX ( FILTER ( _category, Table2[Prof] = 2 ), Table2[Current] ) = "y"
                && MAXX ( FILTER ( _category, Table2[Prof] = 3 ), Table2[Current] ) = "y"
                && OR (
                    MAXX ( FILTER ( _category, Table2[Prof] = 4 ), Table2[Current] ) = "y",
                    MAXX ( FILTER ( _category, Table2[Prof] = 5 ), Table2[Current] ) = "y"
                ),
            "Yes",
            "No"
        )
    

     

  • Hi Kruz_R ,

     

    Try this as a calculated column in table 1

     

    test =
    VAR __1 =
        CALCULATE (
            MAX ( T2[Current] ),
            FILTER ( T2, T2[Prof] = 1 && T2[Employee] = EARLIER ( T1[Employee] ) )
        )
    VAR __2 =
        CALCULATE (
            MAX ( T2[Current] ),
            FILTER ( T2, T2[Prof] = 2 && T2[Employee] = EARLIER ( T1[Employee] ) )
        )
    VAR __3 =
        CALCULATE (
            MAX ( T2[Current] ),
            FILTER ( T2, T2[Prof] = 3 && T2[Employee] = EARLIER ( T1[Employee] ) )
        )
    VAR __4 =
        CALCULATE (
            MAX ( T2[Current] ),
            FILTER ( T2, T2[Prof] = 4 && T2[Employee] = EARLIER ( T1[Employee] ) )
        )
    VAR __5 =
        CALCULATE (
            MAX ( T2[Current] ),
            FILTER ( T2, T2[Prof] = 5 && T2[Employee] = EARLIER ( T1[Employee] ) )
        )
    RETURN
        IF (
            __1 = "y"
                && __2 = "y"
                && __3 = "y"
                && ( __4 = "y"
                || __5 = "y" ),
            "Yes",
            "No"
        )
    

     

    Note: only an inactive relationship exists between the two table.