Forum Discussion
Countifs conatin text
Hi,
I have a one table and it’s contain two columns.
1. If same item has "Not Okay" then return "Not Okay". 2. If same item has "Not Okay" and Orange then return "Not Okay".
2. If same item has Orange then return Orange.
3. If same item has Green then return Green.
4. If same item has Orange or Green in this case return Green
I am trying to attempt below DAX code but “The True/False expression does not specify a column. Each True/False expressions used as a table filter expression must refer to exactly one column.”
I am looking for new calculate column (DAX)
In Excel I applying the following formula =IF(COUNTIFS($A$3:$A$101,$A3,$B$3:$B$101,"Not Okay"),"Not Okay",IF(COUNTIFS($A$3:$A$101,$A3,$B$3:$B$101,"Orange")=COUNTIFS($A$3:$A$101,$A3),$B3,"Green")). I would like to apply the same logic in PBI but I am receiving error
https://www.dropbox.com/s/q4rn361y01r40x2/Countifs%20contain%20text-26-09-21.pbix?dl=0
Data:
| Item | Code | Desired Result |
| 123 | Orange | Orange |
| 124 | Green | Green |
| 125 | Orange | Orange |
| 126 | Green | Green |
| 127 | Orange | Orange |
| 128 | Orange | Orange |
| 135 | Orange | Green |
| 135 | Green | Green |
| 136 | Not Okay | Not Okay |
| 136 | Not Okay | Not Okay |
| 137 | Orange | Orange |
| 137 | Orange | Orange |
| 137 | Orange | Orange |
| 138 | Green | Green |
| 138 | Orange | Green |
| 138 | Orange | Green |
| 139 | Orange | Orange |
| 139 | Orange | Orange |
| 140 | Green | Green |
| 140 | Orange | Green |
| 141 | Orange | Orange |
| 141 | Orange | Orange |
| 141 | Orange | Orange |
| 142 | Green | Green |
| 142 | Orange | Green |
| 142 | Orange | Green |
| 143 | Green | Green |
| 143 | Green | Green |
| 143 | Orange | Green |
| 144 | Not Okay | Not Okay |
| 144 | Not Okay | Not Okay |
| 144 | Orange | Not Okay |
| 145 | Not Okay | Not Okay |
| 145 | Not Okay | Not Okay |
| 145 | Not Okay | Not Okay |
| 145 | Not Okay | Not Okay |
| 147 | Green | Green |
| 147 | Green | Green |
| 148 | Orange | Orange |
| 148 | Orange | Orange |
| 149 | Green | Green |
| 149 | Green | Green |
| 150 | Orange | Orange |
| 150 | Orange | Orange |
| 151 | Green | Green |
| 151 | Green | Green |
| 152 | Orange | Orange |
| 152 | Orange | Orange |
| 152 | Orange | Orange |
| 153 | Not Okay | Not Okay |
| 153 | Not Okay | Not Okay |
| 153 | Orange | Not Okay |
| 1999 | Not Okay | Not Okay |
| 1999 | Not Okay | Not Okay |
| 1999 | Orange | Not Okay |
| 155 | Green | Not Okay |
| 155 | Not Okay | Not Okay |
| 156 | Orange | Green |
| 156 | Green | Green |
| 157 | Orange | Orange |
| 157 | Orange | Orange |
| 154 | Not Okay | Not Okay |
| 154 | Orange | Not Okay |
| 154 | Not Okay | Not Okay |
| 155 | Not Okay | Not Okay |
| 155 | Green | Not Okay |
| 155 | Orange | Not Okay |
| 156 | Orange | Green |
| 156 | Green | Green |
| 156 | Orange | Green |
| 156 | Orange | Green |
| 198 | Not Okay | Not Okay |
| 198 | Not Okay | Not Okay |
| 198 | Not Okay | Not Okay |
| 198 | Not Okay | Not Okay |
| 198 | Not Okay | Not Okay |
| 200 | Green | Green |
| 200 | Green | Green |
| 200 | Green | Green |
| 200 | Green | Green |
| 200 | Green | Green |
| 200 | Green | Green |
| 198 | Not Okay | Not Okay |
| 198 | Not Okay | Not Okay |
| 198 | Not Okay | Not Okay |
| 198 | Not Okay | Not Okay |
| 198 | Not Okay | Not Okay |
| 21111 | Not Okay | Not Okay |
| 21111 | Not Okay | Not Okay |
| 21111 | Not Okay | Not Okay |
| 21111 | Not Okay | Not Okay |
| 21111 | Not Okay | Not Okay |
| 21111 | Not Okay | Not Okay |
| 21111 | Not Okay | Not Okay |
| 21111 | Not Okay | Not Okay |
| 21111 | Not Okay | Not Okay |
| 21111 | Not Okay | Not Okay |
| 21111 | Not Okay | Not Okay |
| 21111 | Orange | Not Okay |
Saxon10 tweak my DAX expression as below:
Answer1 = VAR __code = Report[Item] VAR __table = CALCULATETABLE ( Data, Data[Item] = __code ) VAR __noOk = COUNTX ( __table, IF ( [Code] = "Not Okay", 1 ) ) VAR __orange = COUNTX ( __table, IF ( [Code] = "Orange", 1 ) ) VAR __green = COUNTX ( __table, IF ( [Code] = "Green", 1 ) ) RETURN SWITCH ( TRUE(), NOT ISBLANK ( __noOk ), "Not Okay", NOT ISBLANK ( __orange ) && NOT ISBLANK ( __green ), "Green", NOT ISBLANK ( __orange ), "Orange", NOT ISBLANK ( __green ), "Green", "Unknown" )✨ Follow us on LinkedIn
Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡ Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚡
Hi,
Write this calculated column formula in the Report worksheet
Answer = if(CALCULATE(COUNTROWS(DATA),FILTER(DATA,DATA[ITEM]=EARLIER(REPORT[ITEM])))=0,"NA",if(CALCULATE(COUNTROWS(DATA),FILTER(DATA,DATA[ITEM]=EARLIER(REPORT[ITEM])&&DATA[CODE]="Not Okay"))>=1,"Not Okay",IF(CALCULATE(COUNTROWS(DATA),FILTER(DATA,DATA[ITEM]=EARLIER(REPORT[ITEM])))=CALCULATE(COUNTROWS(DATA),FILTER(DATA,DATA[ITEM]=EARLIER(REPORT[ITEM])&&DATA[CODE]="Orange")),"Orange","Green")))Hope this helps.
8 Replies
- parry2k
Super User
Saxon10 add new column using following expression:
Answer = VAR __code = Data[Item] VAR __table = CALCULATETABLE ( Data, ALL ( Data ), Data[Item] = __code ) VAR __noOk = COUNTX ( __table, IF ( [Code] = "Not Okay", 1 ) ) VAR __orange = COUNTX ( __table, IF ( [Code] = "Orange", 1 ) ) VAR __green = COUNTX ( __table, IF ( [Code] = "Green", 1 ) ) RETURN SWITCH ( TRUE(), NOT ISBLANK ( __noOk ), "Not Okay", NOT ISBLANK ( __orange ) && NOT ISBLANK ( __green ), "Green", NOT ISBLANK ( __orange ), "Orange", NOT ISBLANK ( __green ), "Green", "Unknown" )✨ Follow us on LinkedIn
Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡ Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚡
- Ashish_Mathur
Super User
Hi,
This calculated column formula works
=if(CALCULATE(COUNTROWS(Data),FILTER(Data,Data[Item]=EARLIER(Data[Item])&&Data[Code]="Not Okay"))>=1,"Not Okay",IF(CALCULATE(COUNTROWS(Data),FILTER(Data,Data[Item]=EARLIER(Data[Item])))=CALCULATE(COUNTROWS(Data),FILTER(Data,Data[Item]=EARLIER(Data[Item])&&Data[Code]="Orange")),"Orange","Green"))Hope this helps.
- Saxon10
Post Prodigy
Ashish_Mathur and parry2k ,
Thanks for your solution. The both solution is working well.
I need one more advise please. I would like to get the same result with in-between two tables.
I have a two tables data and Report. The both tables item columns has duplicated.
I would like to pull the colour code from data table into report table according to the item.
1. If same item has "Not Okay" then return "Not Okay". 2. If same item has "Not Okay" and Orange then return "Not Okay".
2. If same item has Orange then return Orange.
3. If same item has Green then return Green.
4. If same item has Orange or Green in this case return Green5. If Item can't found in data table then return "NA".
Some of the item 2 times repeated in data table but in report table maybe it's unique. Example -135.
PBI file attached for your reference.
https://www.dropbox.com/s/fjc544dmnk6jiie/Countifs%20contain%20text-1-26-09-21.pbix?dl=0
- Ashish_Mathur
Super User
Hi,
Write this calculated column formula in the Report worksheet
Answer = if(CALCULATE(COUNTROWS(DATA),FILTER(DATA,DATA[ITEM]=EARLIER(REPORT[ITEM])))=0,"NA",if(CALCULATE(COUNTROWS(DATA),FILTER(DATA,DATA[ITEM]=EARLIER(REPORT[ITEM])&&DATA[CODE]="Not Okay"))>=1,"Not Okay",IF(CALCULATE(COUNTROWS(DATA),FILTER(DATA,DATA[ITEM]=EARLIER(REPORT[ITEM])))=CALCULATE(COUNTROWS(DATA),FILTER(DATA,DATA[ITEM]=EARLIER(REPORT[ITEM])&&DATA[CODE]="Orange")),"Orange","Green")))Hope this helps.
- parry2k
Super User
Saxon10 tweak my DAX expression as below:
Answer1 = VAR __code = Report[Item] VAR __table = CALCULATETABLE ( Data, Data[Item] = __code ) VAR __noOk = COUNTX ( __table, IF ( [Code] = "Not Okay", 1 ) ) VAR __orange = COUNTX ( __table, IF ( [Code] = "Orange", 1 ) ) VAR __green = COUNTX ( __table, IF ( [Code] = "Green", 1 ) ) RETURN SWITCH ( TRUE(), NOT ISBLANK ( __noOk ), "Not Okay", NOT ISBLANK ( __orange ) && NOT ISBLANK ( __green ), "Green", NOT ISBLANK ( __orange ), "Orange", NOT ISBLANK ( __green ), "Green", "Unknown" )✨ Follow us on LinkedIn
Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡ Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚡
- Saxon10
Post Prodigy