Forum Discussion

vissvess's avatar
vissvess
Helper V
6 years ago
Solved

Calculated column for work hour

Hi,

 

My dataset is as follows.

Dataset

 

 

 

 

 

 

 

 

 

 

I need a column that is work hour index.

For example, for a particular day, particular unit status, the earliest of time is hour1 and then the next earliest is hour 2.
the value should be calculated per unit status in a day.

 

Any workaround would be much appreciated.

 

Thanks

  • Thanks AlB for the effort. Also, I'll try to share the table model in further post. Sharing PBIX would not be possible.

     

    The following code worked out.

    Work Hour =
    VAR currentdate =
        CALCULATE ( MIN ( 'Build routing'[Date] ) )
    VAR mintime =
        CALCULATE (
            MIN ( 'Build routing'[End Time] ),
            ALLEXCEPT (
                'Build routing',
                'Build routing'[Date],
                'Build routing'[Unit Status]
            )
        )
    VAR starthour =
        HOUR ( mintime )
    VAR currenthour =
        HOUR ( 'Build routing'[End Time] )
    RETURN
        currenthour - starthour + 1

    This code resulted in the following 

     

     

     

     

     

     

    Thanks for the effort.

2 Replies

  • AlB's avatar
    AlB
    Community Champion

    Hi vissvess 

    Please always show your sample data in text-tabular format in addition to (or instead of) the screen captures. A screen cap doesn't allow people to readily copy the data and run a quick test and thus decreases the likelihood of your question being answered. Just use 'Copy table' in Power BI and paste it here. Or, ideally, share the pbix (beware of confidential data).

    Try this (untested)

    NewCol =
    RANKX (
        FILTER (
            Table1,
            Table1[Date] = EARLIER ( Table1[Date] ) && Table1[Unit Status] = EARLIER ( Table1[Unit Status] )
        ),
        Table1[Start Time],
        ,
        DESC
    )
    

     

    Please mark the question solved when done and consider giving kudos if posts are helpful.

    Cheers  Datanaut

    • vissvess's avatar
      vissvess
      Helper V

      Thanks AlB for the effort. Also, I'll try to share the table model in further post. Sharing PBIX would not be possible.

       

      The following code worked out.

      Work Hour =
      VAR currentdate =
          CALCULATE ( MIN ( 'Build routing'[Date] ) )
      VAR mintime =
          CALCULATE (
              MIN ( 'Build routing'[End Time] ),
              ALLEXCEPT (
                  'Build routing',
                  'Build routing'[Date],
                  'Build routing'[Unit Status]
              )
          )
      VAR starthour =
          HOUR ( mintime )
      VAR currenthour =
          HOUR ( 'Build routing'[End Time] )
      RETURN
          currenthour - starthour + 1

      This code resulted in the following 

       

       

       

       

       

       

      Thanks for the effort.