Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
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
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.
Schedule a short Teams meeting to discuss your question
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
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.
Schedule a short Teams meeting to discuss your question
User | Count |
---|---|
82 | |
79 | |
65 | |
48 | |
45 |
User | Count |
---|---|
103 | |
44 | |
39 | |
39 | |
39 |