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
Anonymous
Not applicable

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
v-eachen-msft
Community Support
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" ) )
        )
    )

 

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

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

MFelix
Super User
Super User

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
)

Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

@MFelix This doesn't work

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


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



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.