Forum Discussion
How to validate numbers between 7 and 9?
Flag= IF(VALUES(CCID_Data[conflict_notes_sk]) > 7 && CCID_Data[conflict_notes_sk] < 9 && CCID_Data[conflict_notes_sk] = all numbers, "Good", "Wrong")
Hopefully, this makes sense. Please let me know.
You can do this in the query editor too by adding a custom column with a formula like this (even though it has a "let" and "in" the whole thing goes in the pop up box when you add custom column.
= let midpart = Text.BetweenDelimiters([Note],"-","-")
in if Text.Length(midpart)<=9 and Text.Length(midpart)>=7 and (try Number.FromText(midpart) otherwise "error") <> "error" then "Valid" else "Invalid"Or you can do it in a DAX column with a formula like this
Valid =
VAR firsthyphen =
SEARCH (
"-",
Validate[Note],
,
0
)
VAR secondhyphen =
SEARCH (
"-",
Validate[Note],
firsthyphen + 1,
0
)
VAR textbetween =
MID (
Validate[Note],
firsthyphen + 1,
secondhyphen - firsthyphen - 1
)
RETURN
IF (
LEN ( textbetween ) >= 7
&& LEN ( textbetween ) <= 9
&& IFERROR (
VALUE ( textbetween ),
"error"
) <> "error",
"Y",
"N"
)
Regards,
Pat
4 Replies
- mahoneypat
Microsoft Employee
You can do this in the query editor too by adding a custom column with a formula like this (even though it has a "let" and "in" the whole thing goes in the pop up box when you add custom column.
= let midpart = Text.BetweenDelimiters([Note],"-","-")
in if Text.Length(midpart)<=9 and Text.Length(midpart)>=7 and (try Number.FromText(midpart) otherwise "error") <> "error" then "Valid" else "Invalid"Or you can do it in a DAX column with a formula like this
Valid =
VAR firsthyphen =
SEARCH (
"-",
Validate[Note],
,
0
)
VAR secondhyphen =
SEARCH (
"-",
Validate[Note],
firsthyphen + 1,
0
)
VAR textbetween =
MID (
Validate[Note],
firsthyphen + 1,
secondhyphen - firsthyphen - 1
)
RETURN
IF (
LEN ( textbetween ) >= 7
&& LEN ( textbetween ) <= 9
&& IFERROR (
VALUE ( textbetween ),
"error"
) <> "error",
"Y",
"N"
)
Regards,
Pat
- AnonymousNot applicable
Hi mahoneypat ,
This is awesome, Thank you so much for the taking time to help me. Do you know I am getting a data type error on the second option?
- mahoneypat
Microsoft Employee
You must have values that don't hany any hyphens and the SEARCH is returning 0. MID throws an error when the 2nd term/start position is 0. You will need to update the logic to avoid that scenario.
Regards,
Pat
- AnonymousNot applicable
Hi mahoneypat , Thank you so much. I appreciate your help.