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
Anonymous
Not applicable

Identify format type in if formula

Hello,

I have an imported column from Excel that contains 2 different data types and I want to convert them into decimal hour.

My idea is to use a if function to identify the data type and apply a formula depending on the data type.

 

The table below shows the different type and the expected result:

 

Original ColumnExpected result
08:00                       8,00
0,21875                       5,25

 

The formula I'm trying to find could be something like: If(datatype=Date(hours:minutes) then formula1 else formula2)

But I'm unable to find how to return a data type in a formula...

 

Any idea please ?

 

Thanks,

Tof.

1 ACCEPTED SOLUTION
v-jingzhan-msft
Community Support
Community Support

Hi @Anonymous 

 

In Power BI, data in a column should have only one data type. So when you load this data from Excel into Power BI, you'd better keep the original column as Text type. Then add a new column by identifying whether a data has a specific symbol like ":" to identify its format. Then make different calculations accordingly. 

For example, this is a DAX solution:

Column =
IF (
    CONTAINSSTRING ( 'Table'[Original column], ":" ),
    VALUE ( LEFT ( 'Table'[Original column], 2 ) ),
    VALUE ( 'Table'[Original column] ) * 24
)

vjingzhanmsft_0-1707210997882.png

 

Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Thanks @v-jingzhan-msft ,

Exactly what I needed !... 👍

v-jingzhan-msft
Community Support
Community Support

Hi @Anonymous 

 

In Power BI, data in a column should have only one data type. So when you load this data from Excel into Power BI, you'd better keep the original column as Text type. Then add a new column by identifying whether a data has a specific symbol like ":" to identify its format. Then make different calculations accordingly. 

For example, this is a DAX solution:

Column =
IF (
    CONTAINSSTRING ( 'Table'[Original column], ":" ),
    VALUE ( LEFT ( 'Table'[Original column], 2 ) ),
    VALUE ( 'Table'[Original column] ) * 24
)

vjingzhanmsft_0-1707210997882.png

 

Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

PijushRoy
Super User
Super User

Hi @Anonymous 

How 0,21875 is calculated as 5.25, please share




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





Anonymous
Not applicable

Thanks for you answer vicky_.

I'll have a look at the article to see if I can find a solution.

vicky_
Super User
Super User

There is no real way to detect the data type in Power Query, but what you can do is to try and convert your String to a date datatype, and catch errors to handle (this isn't best practice, but it works). Here is an article that might help you generate some ideas on how to do that: https://learn.microsoft.com/en-us/power-query/error-handling

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.