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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
vissvess
Helper V
Helper V

Calculated column for work hour

Hi,

 

My dataset is as follows.

DatasetDataset

 

 

 

 

 

 

 

 

 

 

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

1 ACCEPTED SOLUTION

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 

Initial5.JPG

 

 

 

 

 

 

Thanks for the effort.

View solution in original post

2 REPLIES 2
AlB
Community Champion
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

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 

Initial5.JPG

 

 

 

 

 

 

Thanks for the effort.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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