cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
vamshik153 Helper V
Helper V

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 5
Super User III
Super User III

Re: get column based on multiple if conditions

Hi @vamshik153 ,

 

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
)

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

Check out my blog:

Power BI em Português





vamshik153 Helper V
Helper V

Re: get column based on multiple if conditions

@MFelix This doesn't work

Super User III
Super User III

Re: get column based on multiple if conditions

Hi @vamshik153 ,

 

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


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

Check out my blog:

Power BI em Português





Community Support
Community Support

Re: get column based on multiple if conditions

Hi @vamshik153 ,

 

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" ) )
        )
    )

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
vamshik153 Helper V
Helper V

Re: get column based on multiple if conditions

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

Helpful resources

Announcements
Announcing the New Spanish Forum

Announcing the New Spanish Forum

Do you need help in Spanish? Check out our new Spanish community section.

April 2020 Community Highlights

April 2020 Community Highlights

Info on our Super Users, MBAS content and badges, and updates to our support articles. - Read the full Community Highlights.

MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

Top Solution Authors
Top Kudoed Authors