Forum Discussion

alicek's avatar
alicek
Icon for Helper III rankHelper III
3 years ago
Solved

Use SELECTEDVALUE to return 1 value from 1 column based on a shared key field to another table?

Hi all,    We have one key field called DEPARTMENT across three tables: a reference table and two different fact tables. The reference table is just a list of each unique DEPARTMENT, plus one row ...
  • danextian's avatar
    3 years ago

    Hi alicek 

    The first formula below will match what is in Visual2. But I am curious why there is no DPT1 in your expected result when you selected DPT1 and for that is another formula.

    Percent = 
    VAR __DPT =
        SELECTEDVALUE ( reference[DPT] )
    RETURN
        IF (
            SELECTEDVALUE ( table2[DPT] ) = "CIT",
            CALCULATE ( MAX ( table1[Percent] ), FILTER ( table1, table1[DPT] = __DPT ) )
        )
    
    Percent2 = 
    VAR __DPT =
        SELECTEDVALUE ( reference[DPT] )
    RETURN
        IF (
            SELECTEDVALUE ( table2[DPT] ) = "CIT",
            CALCULATE ( MAX ( table1[Percent] ), FILTER ( table1, table1[DPT] = __DPT ) ),
            CALCULATE (
                MAX ( table1[Percent] ),
                FILTER ( table1, table1[DPT] = __DPT ),
                FILTER ( table2, table2[DPT] = __DPT )
            )
        )