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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Create Hour from Text

Hi,

what I am trying to do is to create a new column (measure) that will calculate the differences between pick begin AND pick end. The result should be in minutes.

 

The format is like below:

 

 pick begin  pick end result
1145121833
2110212515
190719070
071007100
032103332
1621163413
1334140127
0135014712
233623360

 

1 ACCEPTED SOLUTION

@Anonymous 
This is not my measure. You can also try by defining a new column as per the calculated column code that I've provided

1.png

DEFINE
COLUMN 'Pick Order'[Column Result] =
VAR PickBegin =
    VALUE ( RIGHT ( 'Pick Order'[PICK Time pick begin], 2 ) ) + 60 * VALUE ( LEFT ( 'Pick Order'[PICK Time pick begin], 2 ) )
VAR PickEnd =
    VALUE ( RIGHT ( 'Pick Order'[PICK Time pick end], 2 ) ) + 60 * VALUE ( LEFT ( 'Pick Order'[PICK Time pick end], 2 ) )
RETURN
    PickEnd - PickBegin

EVALUATE
SUMMARIZECOLUMNS (
    'Pick Order'[PICK Time pick begin],
    'Pick Order'[PICK Time pick end],
    'Pick Order'[Column Result]
)

View solution in original post

10 REPLIES 10
Anonymous
Not applicable

Thank you all for your reply. I am using ReportBuilder, testing in DaxStudio. Working on PowerBI DataSets.

 

And does not matter which of your solution I will choose I am receiving errors like:

"The result set of a query to external data source has exceeded the maximum allowed size"

 

DAX code:

DEFINE

MEASURE 'Pick Measures'[Time]

VAR _hourbegin =
    LEFT ( SELECTEDVALUE (  'Pick Order'[PICK Time pick begin]), 2 )
VAR _minbegin =
    RIGHT ( SELECTEDVALUE (  'Pick Order'[PICK Time pick begin] ), 2 )
VAR _hourend =
    LEFT ( SELECTEDVALUE ( 'Pick Order'[PICK Time pick end] ), 2 )
VAR _minend =
    RIGHT ( SELECTEDVALUE ( 'Pick Order'[PICK Time pick end] ), 2 )
VAR _timebegin = _hourbegin * 60 + _minbegin
VAR _timeend = _hourend * 60 + _minend
RETURN
    _timeend - _timebegin

EVALUATE
SUMMARIZECOLUMNS (

    'Pick DC'[PDC Number],
    'Pick Date'[PD Date],
    'Pick Order'[PICK Order number],
    'Pick Order'[PICK Order pickgroup],
    'Sales Order'[SO Order Number],
    'Material'[MAT Temperature Zone Description],
     'Material'[MAT Business ID],
    'Pick Order'[PICK Time pick begin],
    'Pick Order'[PICK Time pick end],
    'Employee'[EMPL Name],
    FILTER (
        VALUES ( 'Pick DC'[PDC Country] ),
        'Pick DC'[PDC Country] = "USA"
    ),
    FILTER (
        VALUES ( 'Pick DC'[PDC Number] ),
        'Pick DC'[PDC Number] <> 100
    ),
    FILTER (
        'Pick Date',
        'Pick Date'[PD Date]
            = TODAY () - 1
    ),
    
    "Picked Quantity", [Picked Quantity],
    "Picked Net Weight (Kg)", [Picked Net Weight (Kg)],
    "Picked Gross Weight (Kg)", [Picked Gross Weight (Kg)],
    "Time",'Pick Measures'[Time]

)

tamerj1
Super User
Super User

Hi @Anonymous 
Here is a sample file with the solution https://www.dropbox.com/t/OmLvgOdd6iXtXTbt

For a calculated column 

Result = 
VAR PickBegin =
    VALUE ( RIGHT ( Timing[ pick begin ], 2 ) ) + 60 * VALUE ( LEFT ( Timing[ pick begin ], 2 ) )
VAR PickEnd =
    VALUE ( RIGHT ( Timing[ pick end ], 2 ) ) + 60 * VALUE ( LEFT ( Timing[ pick end ], 2 ) )
RETURN
    PickEnd - PickBegin

1.png

For a measure

Result Measure = 
VAR PickBegin =
    SUMX (
        Timing,
        VALUE ( RIGHT ( Timing[ pick begin ], 2 ) ) + 60 * VALUE ( LEFT ( Timing[ pick begin ], 2 ) )
    )
VAR PickEnd =
    SUMX (
        Timing,
        VALUE ( RIGHT ( Timing[ pick end ], 2 ) ) + 60 * VALUE ( LEFT ( Timing[ pick end ], 2 ) )
    )
RETURN
    PickEnd - PickBegin

2.png

Anonymous
Not applicable

Thank you all for your reply. I am using ReportBuilder, testing in DaxStudio. Working on PowerBI DataSets.

 

And does not matter which of your solution I will choose I am receiving errors like:

"The result set of a query to external data source has exceeded the maximum allowed size"

 

DAX code:

DEFINE

MEASURE 'Pick Measures'[Time] 

VAR _hourbegin =
    LEFT ( SELECTEDVALUE (  'Pick Order'[PICK Time pick begin]), 2 )
VAR _minbegin =
    RIGHT ( SELECTEDVALUE (  'Pick Order'[PICK Time pick begin] ), 2 )
VAR _hourend =
    LEFT ( SELECTEDVALUE ( 'Pick Order'[PICK Time pick end] ), 2 )
VAR _minend =
    RIGHT ( SELECTEDVALUE ( 'Pick Order'[PICK Time pick end] ), 2 )
VAR _timebegin = _hourbegin * 60 + _minbegin
VAR _timeend = _hourend * 60 + _minend
RETURN
    _timeend - _timebegin

EVALUATE
SUMMARIZECOLUMNS (

    'Pick DC'[PDC Number],
    'Pick Date'[PD Date],
    'Pick Order'[PICK Order number],
    'Pick Order'[PICK Order pickgroup],
    'Sales Order'[SO Order Number],
    'Material'[MAT Temperature Zone Description],
     'Material'[MAT Business ID],
    'Pick Order'[PICK Time pick begin],
    'Pick Order'[PICK Time pick end],
    'Employee'[EMPL Name],
    FILTER (
        VALUES ( 'Pick DC'[PDC Country] ),
        'Pick DC'[PDC Country] = "USA"
    ),
    FILTER (
        VALUES ( 'Pick DC'[PDC Number] ),
        'Pick DC'[PDC Number] <> 100
    ),
    FILTER (
        'Pick Date',
        'Pick Date'[PD Date]
            = TODAY () - 1
    ),
    
    "Picked Quantity", [Picked Quantity],
    "Picked Net Weight (Kg)", [Picked Net Weight (Kg)],
    "Picked Gross Weight (Kg)", [Picked Gross Weight (Kg)],
    "Time",'Pick Measures'[Time]

)

@Anonymous 
This is not my measure. You can also try by defining a new column as per the calculated column code that I've provided

1.png

DEFINE
COLUMN 'Pick Order'[Column Result] =
VAR PickBegin =
    VALUE ( RIGHT ( 'Pick Order'[PICK Time pick begin], 2 ) ) + 60 * VALUE ( LEFT ( 'Pick Order'[PICK Time pick begin], 2 ) )
VAR PickEnd =
    VALUE ( RIGHT ( 'Pick Order'[PICK Time pick end], 2 ) ) + 60 * VALUE ( LEFT ( 'Pick Order'[PICK Time pick end], 2 ) )
RETURN
    PickEnd - PickBegin

EVALUATE
SUMMARIZECOLUMNS (
    'Pick Order'[PICK Time pick begin],
    'Pick Order'[PICK Time pick end],
    'Pick Order'[Column Result]
)
Anonymous
Not applicable

Thank you, that is perfect! 

CNENFRNL
Community Champion
Community Champion

It's supposed to use PQ to conduct such a data shaping task.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Jc3BDcAwCAPAXXj3gTFJ2lmi7L9GY3iZkxHsbUAOewyB186zLQC/DsQo4/OlXiH7qr6izIBMsvdnGZPZ5h2u09H7oP45su8FOfVPcc4P", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"pick begin" = _t, #"pick end" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"pick begin", Int64.Type}, {"pick end", Int64.Type}}),

    TotalMinutes = Table.AddColumn(#"Changed Type", "Total Minutes",
        each let
                begin=#time(Number.IntegerDivide([pick begin],100), Number.Mod([pick begin],100),0),
                end = #time(Number.IntegerDivide([pick end],100), Number.Mod([pick end],100),0)
            in Duration.TotalMinutes(end-begin)
    )
in
    TotalMinutes

 

CNENFRNL_0-1652382058512.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Anonymous
Not applicable

Hi, thank you. I am not able to use PQ

Jihwan_Kim
Super User
Super User

Hi,

Please check the below measure and the attached pbix file.

 

Result measure: =
VAR _hourbegin =
    LEFT ( SELECTEDVALUE ( Data[pick begin] ), 2 )
VAR _minbegin =
    RIGHT ( SELECTEDVALUE ( Data[pick begin] ), 2 )
VAR _hourend =
    LEFT ( SELECTEDVALUE ( Data[pick end] ), 2 )
VAR _minend =
    RIGHT ( SELECTEDVALUE ( Data[pick end] ), 2 )
VAR _timebegin = _hourbegin * 60 + _minbegin
VAR _timeend = _hourend * 60 + _minend
RETURN
    _timeend - _timebegin

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Greg_Deckler
Community Champion
Community Champion

@Anonymous Maybe this and make sure you set the Data type to Whole number:

result = (TIME(LEFT([pick end],2), RIGHT([pick end],2),0) - TIME(LEFT([pick begin],2), RIGHT([pick begin],2),0)) * 60 * 24

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thank you all for your reply. I am using ReportBuilder, testing in DaxStudio. Working on PowerBI DataSets.

 

And does not matter which of your solution I will choose I am receiving errors like:

"The result set of a query to external data source has exceeded the maximum allowed size"

 

DAX code:

DEFINE

MEASURE 'Pick Measures'[Time] 

VAR _hourbegin =
    LEFT ( SELECTEDVALUE (  'Pick Order'[PICK Time pick begin]), 2 )
VAR _minbegin =
    RIGHT ( SELECTEDVALUE (  'Pick Order'[PICK Time pick begin] ), 2 )
VAR _hourend =
    LEFT ( SELECTEDVALUE ( 'Pick Order'[PICK Time pick end] ), 2 )
VAR _minend =
    RIGHT ( SELECTEDVALUE ( 'Pick Order'[PICK Time pick end] ), 2 )
VAR _timebegin = _hourbegin * 60 + _minbegin
VAR _timeend = _hourend * 60 + _minend
RETURN
    _timeend - _timebegin

EVALUATE
SUMMARIZECOLUMNS (

    'Pick DC'[PDC Number],
    'Pick Date'[PD Date],
    'Pick Order'[PICK Order number],
    'Pick Order'[PICK Order pickgroup],
    'Sales Order'[SO Order Number],
    'Material'[MAT Temperature Zone Description],
     'Material'[MAT Business ID],
    'Pick Order'[PICK Time pick begin],
    'Pick Order'[PICK Time pick end],
    'Employee'[EMPL Name],
    FILTER (
        VALUES ( 'Pick DC'[PDC Country] ),
        'Pick DC'[PDC Country] = "USA"
    ),
    FILTER (
        VALUES ( 'Pick DC'[PDC Number] ),
        'Pick DC'[PDC Number] <> 100
    ),
    FILTER (
        'Pick Date',
        'Pick Date'[PD Date]
            = TODAY () - 1
    ),
    
    "Picked Quantity", [Picked Quantity],
    "Picked Net Weight (Kg)", [Picked Net Weight (Kg)],
    "Picked Gross Weight (Kg)", [Picked Gross Weight (Kg)],
    "Time",'Pick Measures'[Time]

)

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.