Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
POSPOS
Post Patron
Post Patron

How to create a new calculated column with a condition

Hi All,

I have sample data as below. My requirement is to create a new column with the condition as ,

if a "user name" has "Primary" as one of the value for "Status", then show the "Type" of Primary as the "New Column" value
if a "user name" has "Join" as one of the value for "Status", then show the "Type" of Join as the "New Column" value
if a "user name" has only "N/A" for "Status", then show the "Type" of N/A as the "New Column" value

 

User NameStatusTypeNew Column
APrimaryType_Primary_AType_Primary_A
AJoinType_Join_AType_Primary_A
AN/AType_N/A_AType_Primary_A
BJoinType_Join_BType_Primary_B
BPrimaryType_Primary_BType_Primary_B
CJoinType_Join_CType_Primary_C
CPrimaryType_Primary_CType_Primary_C
CN/AType_N/A_CType_Primary_C
CDualType_Dual_CType_Primary_C
DJoinType_Join_DType_Join_D
DJoinType_Join_DType_Join_D
DN/AType_N/A_DType_Join_D
EN/AType_N/A_EType_N/A_E

 

Can somone please suggest on how to achieve this using DAX?
Thank you.

2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question corretly, but please check the below picture and the attached pbix file.

Jihwan_Kim_0-1746499263935.png

 

 

expected result calculated column = 
VAR _username = data[User Name]
VAR _na =
    FILTER ( data, data[User Name] = _username && data[Status] = "N/A" )
VAR _join =
    FILTER ( data, data[User Name] = _username && data[Status] = "Join" )
VAR _primary =
    FILTER ( data, data[User Name] = _username && data[Status] = "Primary" )
VAR _result =
    SWITCH (
        TRUE (),
        COUNTROWS ( _na ) <> 0, SELECTCOLUMNS ( _na, data[Type] ),
        COUNTROWS ( _join ) <> 0, SELECTCOLUMNS ( _join, data[Type] ),
        COUNTROWS ( _primary ) <> 0, SELECTCOLUMNS ( _primary, data[Type] )
    )
RETURN
    _result

 

    Microsoft MVP
 

 

   


      If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


   


     
        LinkedInVisit my LinkedIn page
     

   


   


     
        Outlook BookingSchedule a short Teams meeting to discuss your question

     

   


 


View solution in original post

v-kpoloju-msft
Community Support
Community Support

Hi @POSPOS,
Thank you for reaching out to the Microsoft fabric community forum. Thank you @Jihwan_Kim, for your inputs on this issue.

After thoroughly reviewing the details you provided, I was able to reproduce the scenario, and it worked on my end. I have used it as sample data on my end and successfully implemented it.    

Measure for creating column in table :

New Column =

VAR CurrentUser = 'Table'[User Name]



-- Get the "Type" where Status is "Primary"

VAR PrimaryType =

    CALCULATE(

        MAX('Table'[Type]),

        FILTER('Table', 'Table'[User Name] = CurrentUser && 'Table'[Status] = "Primary")

    )



-- If no "Primary", get the "Type" where Status is "Join"

VAR JoinType =

    CALCULATE(

        MAX('Table'[Type]),

        FILTER('Table', 'Table'[User Name] = CurrentUser && 'Table'[Status] = "Join")

    )



-- If no "Primary" or "Join", get the "Type" where Status is "N/A"

VAR NAType =

    CALCULATE(

        MAX('Table'[Type]),

        FILTER('Table', 'Table'[User Name] = CurrentUser && 'Table'[Status] = "N/A")

    )



-- Return value based on priority: Primary > Join > N/A

RETURN

    IF(

        NOT ISBLANK(PrimaryType), PrimaryType,

        IF(

            NOT ISBLANK(JoinType), JoinType,

            NAType

        )

    )


outcome:

vkpolojumsft_0-1746506807294.png

 

I am also including .pbix file for your better understanding, please have a look into it:

If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.

Thank you for using Microsoft Community Forum.

View solution in original post

5 REPLIES 5
v-kpoloju-msft
Community Support
Community Support

Hi @POSPOS,
Thank you for reaching out to the Microsoft fabric community forum. Thank you @Jihwan_Kim, for your inputs on this issue.

After thoroughly reviewing the details you provided, I was able to reproduce the scenario, and it worked on my end. I have used it as sample data on my end and successfully implemented it.    

Measure for creating column in table :

New Column =

VAR CurrentUser = 'Table'[User Name]



-- Get the "Type" where Status is "Primary"

VAR PrimaryType =

    CALCULATE(

        MAX('Table'[Type]),

        FILTER('Table', 'Table'[User Name] = CurrentUser && 'Table'[Status] = "Primary")

    )



-- If no "Primary", get the "Type" where Status is "Join"

VAR JoinType =

    CALCULATE(

        MAX('Table'[Type]),

        FILTER('Table', 'Table'[User Name] = CurrentUser && 'Table'[Status] = "Join")

    )



-- If no "Primary" or "Join", get the "Type" where Status is "N/A"

VAR NAType =

    CALCULATE(

        MAX('Table'[Type]),

        FILTER('Table', 'Table'[User Name] = CurrentUser && 'Table'[Status] = "N/A")

    )



-- Return value based on priority: Primary > Join > N/A

RETURN

    IF(

        NOT ISBLANK(PrimaryType), PrimaryType,

        IF(

            NOT ISBLANK(JoinType), JoinType,

            NAType

        )

    )


outcome:

vkpolojumsft_0-1746506807294.png

 

I am also including .pbix file for your better understanding, please have a look into it:

If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.

Thank you for using Microsoft Community Forum.

Hi @POSPOS,

 

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thank you.

Hi @POSPOS,


I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you.

Hi @POSPOS,

I hope this information is helpful. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, please Accept it as a solution and give it a 'Kudos' so others can find it easily.
Thank you.

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question corretly, but please check the below picture and the attached pbix file.

Jihwan_Kim_0-1746499263935.png

 

 

expected result calculated column = 
VAR _username = data[User Name]
VAR _na =
    FILTER ( data, data[User Name] = _username && data[Status] = "N/A" )
VAR _join =
    FILTER ( data, data[User Name] = _username && data[Status] = "Join" )
VAR _primary =
    FILTER ( data, data[User Name] = _username && data[Status] = "Primary" )
VAR _result =
    SWITCH (
        TRUE (),
        COUNTROWS ( _na ) <> 0, SELECTCOLUMNS ( _na, data[Type] ),
        COUNTROWS ( _join ) <> 0, SELECTCOLUMNS ( _join, data[Type] ),
        COUNTROWS ( _primary ) <> 0, SELECTCOLUMNS ( _primary, data[Type] )
    )
RETURN
    _result

 

    Microsoft MVP
 

 

   


      If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


   


     
        LinkedInVisit my LinkedIn page
     

   


   


     
        Outlook BookingSchedule a short Teams meeting to discuss your question

     

   


 


Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.