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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

convert calclulated column datatype text to decimal number

Hi

 

I created calculated column and its datatype is "text". how to convert it in to whole number or decimal number datatype. I need DAX expression for this?

 

can you please assist?

 

Thanks

Kunuthuri

18 REPLIES 18
abhi9255
Helper II
Helper II

Just select the calulated column from the fields pane and in the formatting pane choose the data type you want.

 

 

2018-06-18_16h29_22.png

 

 

 

Anonymous
Not applicable

Hi

 

Thanks to reply,

 

we created calculated column and its data type and format in text, and change it to decimal , showing error

 

Capture7.PNGCapture8.PNGCapture9.PNG

 

How to rectify it?

 

Thanks

kunuthuri

can you share you dax expression?

Anonymous
Not applicable

calculated column

 

Hours Between = VAR Hrs = DATEDIFF(Table[startdate],'Table'[enddate],HOUR)                                                                                                              VAR Mins = MOD(DATEDIFF( Table[startdate],'Table'[enddate],MINUTE),60)

                           VAR TheTime =

                            IF (Hrs >0, COMBINEVALUES (" " , Hrs, "hrs", Mins, "mins"),

                                             COMBINEVALUES(" " , Mins,"mins"))

                            Return TheTime

You are trying to concate string along with number which cannot be converted into decimal. that is why you are getting the error

Anonymous
Not applicable

Is there any solution?

 

Hi @Anonymous,

 

What's the result you expect? 

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi

 

Finding Hours between start and end date ?

 

Hours Between = VAR Hrs = DATEDIFF(Table[startdate],'Table'[enddate],HOUR)                                                                                                              VAR Mins = MOD(DATEDIFF( Table[startdate],'Table'[enddate],MINUTE),60)

                           VAR TheTime =

                            IF (Hrs >0, COMBINEVALUES (" " , Hrs, "hrs", Mins, "mins"),

                                             COMBINEVALUES(" " , Mins,"mins"))

                            Return TheTime

 

Result :

 

Name      Hours Between

ABC         1 hrs 15 mins

DEF          2 hrs 40 mins

XYZ          10 mins

 

Above query is executed correctly and i need to find total hours in Card visual. So, next i created new measure 

 

Total Hours measure = calculate(sum(table1[Hours Between]), filter (table2,[type]="sample"

 

Once i drag the Total Hours measure in to card visual . it is showing

 

The Function SUM cannot work with values of type string

 

How to resolve this issue. can you please assist?

 

Thanks

Kunuthuri

Hi Kunuthuri,

 

If you don't want to change the format of [Hours Between], maybe you can try the formula below.

Measure =
VAR total =
    SUMX (
        SUMMARIZE (
            'table',
            'table'[Name],
            "seconds", DATEDIFF ( [startdate], [enddate], SECOND )
        ),
        [seconds]
    )
VAR hours =
    INT ( total / 3600 )
VAR minutes =
    INT ( MOD ( total, 3600 ) / 60 )
VAR seconds =
    MOD ( MOD ( total, 3600 ), 60 )
RETURN
    hours & " hours "
        & minutes
        & " minutes "
        & seconds
        & " seconds"

If you want a more accurate formula, please provide a sample.

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi

 

Accurate formula:

 

Finding the hours between startdate and enddate columns in action table.

 

Hours Between = VAR Hrs = DATEDIFF(action[startdate],'action'[enddate],HOUR)                                                                                                        VAR Mins = MOD(DATEDIFF( action[startdate],'action'[enddate],MINUTE),60)

                           VAR TheTime =

                            IF (Hrs >0, COMBINEVALUES (" " , Hrs, "hrs", Mins, "mins"),

                                             COMBINEVALUES(" " , Mins,"mins"))

                            Return TheTime

Once executed the calculated column, it display

 

Name           Hoursbetween

field              30 mins

public           1 hrs 20 mins

 

according to requirement , above Name "field","public" etc... display field total hours and public total hours etc...

 

for this i created new measure 

 

measure = calculate(sum(action[Hoursbetween]) filter(site[name]="field"))

 

excecuted the query and drag it in to card visual it is showing

 

The function SUM cannot work with values of type string

 

thanks

 

 

 

@Anonymous,

 

Seems like you've added more to your original post https://community.powerbi.com/t5/Desktop/when-we-trim-the-left-side-characters-with-data-type-text-in/td-p/437842.

 

The measure

 

Measure =
VAR MINstartdate =
    SUM ( 'Action'[StartTime] )
VAR MAXStartdate =
    SUM ( 'Action'[EndTime] )
VAR hrs =
    DATEDIFF ( MINstartdate, MAXStartdate, HOUR )
VAR mins =
    MOD ( DATEDIFF ( MINstartdate, MAXStartdate, MINUTE ), 60 )
VAR theTime =
    IF (
        hrs > 0
            && mins >= 1,
        COMBINEVALUES ( " ", hrs, "hrs", mins, "mins" ),
        IF (
            hrs > 0,
            COMBINEVALUES ( " ", hrs, "hrs" ),
            COMBINEVALUES ( " ", mins, "mins" )
        )
    )
RETURN
    theTime

seems to be working as you desire, correct?

 

1.PNG






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



Anonymous
Not applicable

Hi

 

Thanks to reply,

 

The Measure you send, once i drag it into any visual like (card, table etc...) it is showing errorCapture11.PNGCapture12.PNG

Hi @Anonymous,

 

Can you share you file? A dummy one is enough.

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi

 

Capture13.PNG

 

before created above measure, action table startdate and enddate columns are in date\time datatype

 

Capture15.PNG

 

once we created new measure , the measure in text data type

 

 

Capture14.PNG

 

then we drag it throwing an error

 

thanks

 

 

Surely, "3 hrs" is not a date. The text type won't be a problem.

Where did you drag it to?

What's wrong with my solution?

Measure =
VAR total =
    SUMX (
        SUMMARIZE (
            'table',
            'table'[Name],
            "seconds", DATEDIFF ( [startdate], [enddate], SECOND )
        ),
        [seconds]
    )
VAR hours =
    INT ( total / 3600 )
VAR minutes =
    INT ( MOD ( total, 3600 ) / 60 )
VAR seconds =
    MOD ( MOD ( total, 3600 ), 60 )
RETURN
    hours & " hours "
        & minutes
        & " minutes "
        & seconds
        & " seconds"

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi

 

Capture16.PNG

 

Above query, name column which column to conider?

I got it from your posts. Can you share a sample? Or how can I know anything else about your data?

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi

 

sample data file.

 

Capture17.PNG

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.