Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

get column based on multiple if conditions

 

Hello All,

Iam working on migration project and have requirment like this:

In a table, i want to display different columns based on different conditions in single dax. For example, if condition-A becomes true , i need to display column1, if cond-2 is true, i want to display column2, if cond-3, column3.....This is working for pie chart visual, but not for table.

Pls let me know solution for this.

For refrence purpose, iam attaching the qlik expression here, which need to be converted to dax.

=if(GetSelectedCount(Direct) > 0 and GetSelectedCount(VP_Director) = 0 and GetSelectedCount(Director_Manager) = 0 and GetSelectedCount(Manager) = 0 , VP_Director, if( (GetSelectedCount(Direct) > 0 and GetSelectedCount(VP_Director) > 0 and GetSelectedCount(Director_Manager) = 0 and GetSelectedCount(Manager) = 0) or (GetSelectedCount(VP_Director) > 0 and GetSelectedCount(Direct) = 0 and GetSelectedCount(Director_Manager) = 0 and GetSelectedCount(Manager) = 0) , Director_Manager, if( (GetSelectedCount(Direct) > 0 and GetSelectedCount(VP_Director) > 0 and GetSelectedCount(Director_Manager) > 0 and GetSelectedCount(Manager) = 0) or (GetSelectedCount(VP_Director) = 0 and GetSelectedCount(Direct) > 0 and GetSelectedCount(Director_Manager) > 0 and GetSelectedCount(Manager) = 0) or (GetSelectedCount(VP_Director) > 0 and GetSelectedCount(Direct) = 0 and GetSelectedCount(Director_Manager) > 0 and GetSelectedCount(Manager) = 0) , Manager, if( (GetSelectedCount(Direct) > 0 and GetSelectedCount(VP_Director) > 0 and GetSelectedCount(Director_Manager) > 0 and GetSelectedCount(Manager) > 0) or (GetSelectedCount(VP_Director) = 0 and GetSelectedCount(Direct) > 0 and GetSelectedCount(Director_Manager) > 0 and GetSelectedCount(Manager) > 0) or (GetSelectedCount(VP_Director) > 0 and GetSelectedCount(Direct) = 0 and GetSelectedCount(Director_Manager) > 0 and GetSelectedCount(Manager) > 0) or (GetSelectedCount(VP_Director) = 0 and GetSelectedCount(Direct) = 0 and GetSelectedCount(Director_Manager) = 0 and GetSelectedCount(Manager) > 0) , SUBAREA_OWNER ))))

[4:41 PM] Vamshi Krishna Nomula
okay

5 Replies

  • Hi Anonymous ,

     

    Try the following code (may need adjustments):

     

    ttt =
    SWITCH (
        TRUE (),
        COUNT ( Table[Direct] ) > 0
            && COUNT ( Table[VP_Director] ) = 0
            && COUNT ( Table[Director_Manager] ) = 0
            && COUNT ( Table[Manager] ) = 0, "VP_Director",
        (
            COUNT ( Table[Direct] ) > 0
                && COUNT ( Table[DirectVP_Director] ) > 0
                && COUNT ( Table[Director_Manager] ) = 0
                && COUNT ( Table[Manager] ) = 0
        )
            || (
                COUNT ( Table[VP_Director] ) > 0
                    && COUNT ( Table[Direct] ) = 0
                    && COUNT ( Table[Director_Manager] ) = 0
                    && COUNT ( Table[Manager] ) = 0
            ), "Director_Manager",
        (
            COUNT ( Table[Direct] ) > 0
                && COUNT ( Table[VP_Director] ) > 0
                && COUNT ( Table[Director_Manager] ) > 0
                && COUNT ( Table[Manager] ) = 0
        )
            || (
                COUNT ( Table[VP_Director] ) = 0
                    && COUNT ( Table[Direct] ) > 0
                    && COUNT ( Table[Director_Manager] ) > 0
                    && COUNT ( Table[Manager] ) = 0
            )
            || (
                COUNT ( Table[VP_Director] ) > 0
                    && COUNT ( Table[Direct] ) = 0
                    && COUNT ( Table[Director_Manager] ) > 0
                    && COUNT ( Table[Manager] ) = 0
            ), "Manager",
        (
            COUNT ( Table[Direct] ) > 0
                && COUNT ( Table[VP_Director] ) > 0
                && COUNT ( Table[Director_Manager] ) > 0
                && COUNT ( Table[Manager] ) > 0
        )
            || (
                COUNT ( Table[VP_Director] ) = 0
                    && COUNT ( Table[Direct] ) > 0
                    && COUNT ( Table[Director_Manager] ) > 0
                    && COUNT ( Table[Manager] ) > 0
            )
            || (
                COUNT ( Table[VP_Director] ) > 0
                    && COUNT ( Table[Direct] ) = 0
                    && COUNT ( Table[Director_Manager] ) > 0
                    && COUNT ( Table[Manager] ) > 0
            )
            || (
                COUNT ( Table[VP_Director] ) = 0
                    && COUNT ( Table[Direct] ) = 0
                    && COUNT ( Table[Director_Manager] ) = 0
                    && COUNT ( Table[Manager] ) > 0
            ), SUBAREA_OWNER
    )
      • MFelix's avatar
        MFelix
        Super User

        Hi Anonymous ,

         

        Can you please share a small smaple of your datafile?

         

        Are this columns on your model? And what type of data do they have?

        Direct, VP_Director, Director_Manager, Manager

  • v-eachen-msft's avatar
    v-eachen-msft
    Community Support

    Hi Anonymous ,

     

    You could try the following DAX:

    Column =
    VAR a =
        COUNT ( 'Table'[Direct] )
    VAR b =
        COUNT ( 'Table'[VP_Director] )
    VAR c =
        COUNT ( 'Table'[Director_Manager] )
    VAR d =
        COUNT ( 'Table'[Manager] )
    RETURN
        IF (
            d > 0,
            "SUBAREA_OWNER",
            IF (
                c > 0,
                "Manager",
                IF ( b > 0, "Director_Manager", IF ( a > 0, "VP_Director" ) )
            )
        )

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      v-eachen-msft Thanks for the help. but this solution doesn't work for requirment