Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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 Name | Status | Type | New Column |
A | Primary | Type_Primary_A | Type_Primary_A |
A | Join | Type_Join_A | Type_Primary_A |
A | N/A | Type_N/A_A | Type_Primary_A |
B | Join | Type_Join_B | Type_Primary_B |
B | Primary | Type_Primary_B | Type_Primary_B |
C | Join | Type_Join_C | Type_Primary_C |
C | Primary | Type_Primary_C | Type_Primary_C |
C | N/A | Type_N/A_C | Type_Primary_C |
C | Dual | Type_Dual_C | Type_Primary_C |
D | Join | Type_Join_D | Type_Join_D |
D | Join | Type_Join_D | Type_Join_D |
D | N/A | Type_N/A_D | Type_Join_D |
E | N/A | Type_N/A_E | Type_N/A_E |
Can somone please suggest on how to achieve this using DAX?
Thank you.
Solved! Go to Solution.
Hi,
I am not sure if I understood your question corretly, but please check the below picture and the attached pbix file.
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
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:
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,
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:
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.
Hi,
I am not sure if I understood your question corretly, but please check the below picture and the attached pbix file.
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
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
69 | |
68 | |
40 | |
29 | |
26 |
User | Count |
---|---|
86 | |
49 | |
45 | |
38 | |
37 |