Forum Discussion
Filter table based on duplicated ID and depending if columns contains value
Hello everyone,
As a beginner, I have a difficulty with a data set and a request that I can resume as such.
I have the following data set and I should retrieve value following these rules:
If Id has a category = "CS" and "MD", return "CS" value (excluding MD value).
Else if there is no "CS" in category for an Id, return the "MD" value.
| Index | Id | Category | Value |
| 1 | A | CS | 5 |
| 2 | A | MD | 10 |
| 3 | B | CS | 6 |
| 4 | B | others | 11 |
5 | C | MD | 7 |
6 | C | other | 12 |
I have difficulty to figure out how resolve this problem without creating additional table but i feel like it could be possible, isn'it ?
thank in advance for any help and comment
- Anonymous1 year ago
Hi All,
Firstly parry2k thank you for youe solution!
And John_Foord , I'm glad to tell you that your needs can be realized, we can go through the MEASUREMENT to achieve your needs, when asking for the value, grouped by ID to ensure that he does not value the display in one line, but rather includes the calculation of this one group.Measure 2 = VAR CS_Count = CALCULATE(COUNTROWS('Table'), 'Table'[Category] = "CS", ALLEXCEPT('Table', 'Table'[Id])) VAR MD_Count = CALCULATE(COUNTROWS('Table'), 'Table'[Category] = "MD", ALLEXCEPT('Table', 'Table'[Id])) VAR CS_Value = CALCULATE(MAX('Table'[Value]), 'Table'[Category] = "CS", ALLEXCEPT('Table', 'Table'[Id])) VAR MD_Value = CALCULATE(MAX('Table'[Value]), 'Table'[Category] = "MD", ALLEXCEPT('Table', 'Table'[Id])) RETURN IF( CS_Count >= 1 && MD_Count >= 1, CS_Value, IF( CS_Count < 1, MD_Value, 0 )Since the second group, does not have a clear logic, I set it to 0 here, so you can make your own changes if you need to.
I hope my thoughts have solved your problem, if you have any further questions, you can always contact me and I will get back to you as soon as I get the message!
Hope it helps!
Best regards,
Community Support Team_ Tom ShenIf this post helps then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- parry2k
Super User
John_Foord try adding new column using following expression, change the expression as you see fit:
New Column = VAR __Id = 'Table (3)'[Id] VAR __Table0 = FILTER ( ALL ( 'Table (3)' ), 'Table (3)'[Id] = __Id ) VAR __Table = SELECTCOLUMNS ( __Table0, [Category] ) VAR __Test = IF ( "CS" IN __Table && "MD" IN __Table, "CS", IF ( NOT "CS" IN __Table, "MD", "Other" ) ) RETURN __Test - AnonymousNot applicable
Hi All,
Firstly parry2k thank you for youe solution!
And John_Foord , I'm glad to tell you that your needs can be realized, we can go through the MEASUREMENT to achieve your needs, when asking for the value, grouped by ID to ensure that he does not value the display in one line, but rather includes the calculation of this one group.Measure 2 = VAR CS_Count = CALCULATE(COUNTROWS('Table'), 'Table'[Category] = "CS", ALLEXCEPT('Table', 'Table'[Id])) VAR MD_Count = CALCULATE(COUNTROWS('Table'), 'Table'[Category] = "MD", ALLEXCEPT('Table', 'Table'[Id])) VAR CS_Value = CALCULATE(MAX('Table'[Value]), 'Table'[Category] = "CS", ALLEXCEPT('Table', 'Table'[Id])) VAR MD_Value = CALCULATE(MAX('Table'[Value]), 'Table'[Category] = "MD", ALLEXCEPT('Table', 'Table'[Id])) RETURN IF( CS_Count >= 1 && MD_Count >= 1, CS_Value, IF( CS_Count < 1, MD_Value, 0 )Since the second group, does not have a clear logic, I set it to 0 here, so you can make your own changes if you need to.
I hope my thoughts have solved your problem, if you have any further questions, you can always contact me and I will get back to you as soon as I get the message!
Hope it helps!
Best regards,
Community Support Team_ Tom ShenIf this post helps then please consider Accept it as the solution to help the other members find it more quickly.