Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
tempranello
Advocate I
Advocate I

Test for a number

Hi there

 

I must be losing it...this seems such a simple thing to do, but I'm blowed if I can sort this out myself.

 

I've a column of type text in a query that may or may not contain text or a number.  I've an if statement in which I'd like to take the content of that column and act one way if the column's content is a number and another way if the content is text.

 

Number.FromText seems like a good place to start as it returns an error if the value is text, but I can't evaluate the error to a boolean value to trigger the if statement either way.  So perhaps I'm barking up the wrong tree.

 

In summary:

 

If column IsANumber then ...

else ...

 

Any thoughts?

 

Thanks!

2 ACCEPTED SOLUTIONS
chrisu
Responsive Resident
Responsive Resident

I think you want to use Value.Is.  To check if a value is text, it would look something like this:

 

Value.Is([Column],type text)

 

To check for a number, it would be:

 

Value.Is([Column], Int64.Type)

 

Value.Is returns a boolean true/false, so you can wrap it in an IF.  

View solution in original post

Anonymous
Not applicable

Worked for me. Thank you!

 

if Value.Is(AlphaNumeric, type text) then AlphaNumeric else Number.ToText(AlphaNumeric))

View solution in original post

10 REPLIES 10
tomasMoreno
New Member

Another take on this, applied to an [Index] column: Divide the value by the "TestMultiple" to test, then round to 0 decimals, then multilply back again and test if resulting value is equal to original value:

[Index] being any column with numbers

[TestMultiple] the factor: 3, 5, 7, etc....

 

Number.Round([Index]/TestMultiple,0)*TestMultiple=[Index])

 

Anonymous
Not applicable

I did not get good results with Value.Is as I did not change the Column to numeric yet. What helped me is this:

try Number.From([Column1])-Number.From([Column1]) otherwise 1

This will be 0 if Column1 is numeric no matter what kind of number it is, and 1 in case of errors. You can add bunch of these together to validate all columns once. If 0 no issues, anything othern than 0 there is an issue. Make sure to replace null values to 0 beforehand on any columns that you are validating.

v-caliao-msft
Microsoft Employee
Microsoft Employee

Hi Tempranell,

 

Please try to add a column use the power query below.
=try Number.From([ColumnA]) otherwise 0
Capture.PNG

Then convert this new created column from text to number
Capture1.PNG

Then add a column using the DAX below.
Text = IF(ConvertToNumber[Number]=0,ConvertToNumber[ColumnA],"")

Capture2.PNG

 

Reference
https://msdn.microsoft.com/en-us/library/mt253315.aspx

 

Regards,

Charlie Liao

chrisu
Responsive Resident
Responsive Resident

I think you want to use Value.Is.  To check if a value is text, it would look something like this:

 

Value.Is([Column],type text)

 

To check for a number, it would be:

 

Value.Is([Column], Int64.Type)

 

Value.Is returns a boolean true/false, so you can wrap it in an IF.  

Anonymous
Not applicable

Worked for me. Thank you!

 

if Value.Is(AlphaNumeric, type text) then AlphaNumeric else Number.ToText(AlphaNumeric))

 

Anonymous
Not applicable

Worked for me. Thank you!

 

if Value.Is(AlphaNumeric, type text) then AlphaNumeric else Number.ToText(AlphaNumeric))
wonga
Continued Contributor
Continued Contributor

Along with @chrisu suggestion, you could also do a try, otherwise statement:

 

try Number.FromText([TEST_COL]) otherwise "FALSE"

 

This will either return a number converted from text or the value of FALSE is TEST_COL is not a number at that particular row.

wonga
Continued Contributor
Continued Contributor

Are you trying to do this through DAX or Power Query?

 

DAX is used for Measures and Power Query is used for Calculated Columns.

Apologies, I'm doing this in Power Query.

wonga
Continued Contributor
Continued Contributor

Can you provide some more context as to what you want to achieve? Provide a sample dataset and what you want the expected result to be.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.