cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
vissvess Member
Member

Calculated column for work hour

Hi,

 

My dataset is as follows.

Initial4.JPGDataset

 

 

 

 

 

 

 

 

 

 

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

Accepted Solutions
vissvess Member
Member

Re: Calculated column for work hour

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.

2 REPLIES 2
Super User
Super User

Re: Calculated column for work hour

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 Member
Member

Re: Calculated column for work hour

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
Community Highlights

Community Highlights

Find out what's new in the Power BI Community!

Summit North America

Power Platform Summit North America

Register by September 5 to save $200

Virtual Launch Event

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Top Kudoed Authors
Users Online
Currently online: 255 members 2,614 guests
Please welcome our newest community members: