Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

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

 

  • tamerj1's avatar
    tamerj1
    4 years ago

    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

    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]
    )

10 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    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

     

    • Anonymous's avatar
      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]

      )

  • 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
    
  • CNENFRNL's avatar
    CNENFRNL
    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

     

    • Anonymous's avatar
      Anonymous
      Not applicable

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

  • tamerj1's avatar
    tamerj1
    Community Champion

    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

    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

    • Anonymous's avatar
      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's avatar
        tamerj1
        Community Champion

        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

        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's avatar
    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]

    )