Forum Discussion
How to check if column contains numbers an null values PQuery?
Hello to all,
May someone help me with this. I haven't found a function to do this. I have a table with Column2 with type formatted as text (ABC) containing the data shown below. I'd like to have a 3rd Column (Column3) that shows the text "Numbers" when there are only numbers separated by comma in Column2, show the value in Column2 if Column2 not contains numbers and show "Not value" if Column2 = Null/Empty.
| Column1 | Column2 | Column3 |
| 1 | 5,9,774,2,0,22,34,13344,3 | Numbers |
| 2 | John,Mary | John,Mary |
| 3 | No value | |
| 4 | 585,20 | Numbers |
| 5 | Paul,Henry,Joan | Paul,Henry,Joan |
| 6 | 880 | Numbers |
| 7 | June,December | June,December |
| 8 | Apple,Grape,Orange | Apple,Grape,Orange |
| 9 | No value | |
| 10 | 771,3 | Numbers |
Thanks in advance for any help.
Hi cgkas ,
Don't understand why you say expand values after table?
You should add a calculated column, check PBIX file attach.
Also the DAX expression I have place on this post included.
Regards,
MFelix
13 Replies
- Nathaniel_C
Community Champion
Hi cgkas ,
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.
NathanielWhich = var _C1 = LEFT('Status'[Column2],1) var _isnumber =IF('Status'[Column2]="","No Value",IF(_C1 in {"1","2","3","4","5","6","7","8","9","0"},"Numbers", 'Status'[Column2])) return _isnumber- MFelix
Super User
Hi Nathaniel_C ,
Don't want to rain on your parade but believe that this will not get the correct result, what if the cell values is for example "1, ABC, 2" as you are only checking the first character would return number instead of text.
I know that the value is not on the example but is on the question "when there are only numbers separated by comma in Column2".
Using dax should probably use this calculated column:
Column = IF ( 'Table'[Column2] = ""; "No Values"; IF ( IFERROR ( FORMAT ( SUBSTITUTE ( 'Table'[Column2]; "."; "" ); "###" ) + 0; BLANK () ) = BLANK (); 'Table'[Column2]; "Numbers" ) )Sorry for this correction
Regards,
MFelix
- Nathaniel_C
Community Champion
Hi MFelix ,
"show the value in Column2 if Column2 not contains numbers." is what I read.
Thanks, though,
Nathaniel
- cgkas
Helper V
- Nathaniel_C
Community Champion
- MFelix
Super User
Hi cgkas ,
In the query editor add a calculated column with the following code:
= Table.AddColumn(#"Replaced Value", "Custom", each if Value.Is(Value.FromText( Text.Remove([Column2],{","}) ), type number) then "Numbers" else if [Column2] = null then "No Value" else [Column2])Regards,
MFelix
- cgkas
Helper V
Hi Felix,
Thanks for answer and your help. It almost work fine, I get error in the line where Column2= 880.
How to fix this?
Thanks again