Forum Discussion
Translating the IF statement into DAX
- 6 years ago
Hi nursyeha001
Try adding a column with the expression below.
Valid Result = VAR RowFirstName = 'Table'[First Name] VAR RowLastName = 'Table'[Last Name] VAR RowYear = 'Table'[Year] VAR NoOfSubmissions = CALCULATE ( COUNTROWS ( FILTER ( ALL ( 'Table' ), 'Table'[First Name] = RowFirstName && 'Table'[Last Name] = RowLastName && 'Table'[Year] = RowYear ) ) ) VAR Result = SWITCH ( TRUE(), NoOfSubmissions > 1 && 'Table'[Assignments] = "Amended Submission", "Y", NoOfSubmissions = 1, "Y", "N" ) RETURN ResultNote: this expression won't work if you have 2 or more people with the same name in the same year.
Best regards,
Martyn
- 6 years ago
Hi nursyeha001 , MartynRamsden ,
This also will not work if there are more than a max of two entries per year per person. For instance if you had two "Amended Submissions". So, as MartynRamsden points out if two people have the same name this will not work, my suggestion is that you include in your table a unique identifier (an ID), and that you also have month, day, year to figure out which is the latest submission. Or as an alternative to a full date, you could have the submissions numbered, and we would take the maximum submission per unique ID.
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos πare nice too.
Nathaniel
Hi nursyeha001 ,
Your example does not seem to follow your written example. ATR? is not mentioned in the written portion. I also cannot tell if you have multiple tables and the relationships.
If you would share your pbix, or dummy up some values in Excel both for current and expected data. Please copy and paste them into your post, rather than doing a picture, we may be able to help you.
Please read this post to get your question answered more quickly:
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos πare nice too.
Nathaniel
Hi Nathaniel,
It's all in one table that I'm importing into Power BI and need to transform using DAX to create a column, Valid Record, that for each person, looks at the Assignments submitted for the Year and takes the latest version indicated with Y, any earlier versions will be indicated as a N.
Sample Data:
| First Name | Last Name | Year | Assignments | Valid Record |
| Peter | Parker | 2015 | Submission | N |
| Peter | Parker | 2015 | Amended Submission | Y |
| Tony | Stark | 2017 | Submission | Y |
| Bruce | Wayne | 2018 | Submission | N |
| Bruce | Wayne | 2018 | Amended Submission | Y |
Thanks!
Nur
- MartynRamsden6 years agoSolution Sage
Hi nursyeha001
Try adding a column with the expression below.
Valid Result = VAR RowFirstName = 'Table'[First Name] VAR RowLastName = 'Table'[Last Name] VAR RowYear = 'Table'[Year] VAR NoOfSubmissions = CALCULATE ( COUNTROWS ( FILTER ( ALL ( 'Table' ), 'Table'[First Name] = RowFirstName && 'Table'[Last Name] = RowLastName && 'Table'[Year] = RowYear ) ) ) VAR Result = SWITCH ( TRUE(), NoOfSubmissions > 1 && 'Table'[Assignments] = "Amended Submission", "Y", NoOfSubmissions = 1, "Y", "N" ) RETURN ResultNote: this expression won't work if you have 2 or more people with the same name in the same year.
Best regards,
Martyn
- Nathaniel_C6 years agoCommunity Champion
Hi nursyeha001 , MartynRamsden ,
This also will not work if there are more than a max of two entries per year per person. For instance if you had two "Amended Submissions". So, as MartynRamsden points out if two people have the same name this will not work, my suggestion is that you include in your table a unique identifier (an ID), and that you also have month, day, year to figure out which is the latest submission. Or as an alternative to a full date, you could have the submissions numbered, and we would take the maximum submission per unique ID.
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos πare nice too.
Nathaniel