Let’s say you have a time value (either user input or calculated) in cell A1.

**Nearest second**: =TIME(HOUR(A1), MINUTE(A1), SECOND(A1)).

- SECOND formula rounds up any fractions and returns full seconds.

**Nearest 15 seconds: **=TIME(HOUR(A1), MINUTE(A1), MROUND(SECOND(A1),15))

- Use MROUND() to round up seconds values to nearest multiple of 15 (or whatever else)

**Nearest Minute: =**TIME(HOUR(A1), MINUTE(A1)+(SECOND(A1)>30),0)

- The seconds value will always be zero. We just look at fractional minutes portion to see if they are more then 30 to round up to next minute. The trick is to add up Boolean check (SECOND(A1)>30) to minutes value.

**Nearest 15 minutes:** =TIME(HOUR(A1), MROUND(MINUTE(A1)+SECOND(A1)/60,15),0)

- This one uses MROUND to round total mins (including fraction) to nearest multiple of 15.

**Nearest 37th minute: **=TIME(HOUR(A1), MROUND(MINUTE(A1)+SECOND(A1)/60,37),0)

- Same logic. Just to show you how to round to an arbitrary minute.

**Nearest hour:** =TIME(HOUR(A1) +((MINUTE(A1)+SECOND(A1)/60)>30),0,0)

- Check if total minutes is greater than 30 and add the result to hours.

Let’s test your timing skills. Assuming A1 has date & time value (like 26-Jun-2017 7:21:32 AM), round it **up **to nearest working hour.

- The working hours are 9AM to 6PM on weekdays (Monday – Friday)

Post your answers in the comments section. Tick tock, tick tock… time is ticking, post your answers.

*Always having a hard time working with times in Excel?* Its high time you took some time to learn about Excel time.

- Working with date & time values in Excel – a quick intro
- Convert fractional time to hours & minutes
- Highlighting over due items
- 42 tips for Excel time travelers – calculating past, present and future time values using formulas
- Sorting by birthday
- More date & time tips

- Come up with ingenious solutions
- See if a simpler
*cheat*solution is possible - Sit back and ignore

For most problems, I choose 3rd reaction. Occasionally, I rely on 2nd option and very rarely the first one.

When faced with a tricky time sheet summary problem (as outlined below), after initial lethargy I wanted to solve it.

Imagine some time sheet data as shown below. What is the total time each employee worked?

Of course, we can whip up a SUMPRODUCT concoction strong enough to knock off Mike Girvin unconscious* for a few milliseconds to answer the question.

As shown on this forum thread, there are several fun, creative and smart ways to answer each employee’s total duration using such complex formulas.

* Stop kidding yourself. Mike’s tougher than SUMPRODUCT.

We can cheat by first reshaping the data to something like this.

But how? Simple, we take a saw and chisel to the data. I meant power query of course.

Last Friday, I took a wee walk up to Mt. KauKau to enjoy the views and workout my calf muscles. I couldn’t help but share that beautiful moment with you all. So I recorded a video showcasing beautiful views and introducing the problem. Then, I recorded rest of it from the comfort and warmth of my home. So here we go:

Watch it on our YouTube channel.

**Click here to download the example workbook**. Edit any of the queries to see all the steps. Try replicating them yourself to learn more.

Let me confess. My first solution to this problem is based on SUMPRODUCT. But that is because I didn’t have Power Query on that computer. But I later tried solving it with PQ and I just love the simplicity and power of that solution. Anytime I am wrangling poorly shaped data, I use Power Query instead of a mashup of formulas.

**What about you? **Which option do you prefer and why? Please share your thoughts in comments.

Guess what it is?

**F4**.

That is right. The mighty F4 key. You can use it to repeat any action.

Jo was using it to insert rows in her workbook. After inserting first row (using CTRL+ of course), she would press F4 to add more rows as needed.

So next time you find yourself doing the same thing several times, use F4 and save yourself a few keystrokes or mouse moves.

**Your mission: What is your partner’s shortcut of the moment?**

Take a short break from work. Call / message / ask your partner (or friend, mate, parent or kid) what their shortcut of the moment is? Post it here in the comments section.

What… they don’t use Excel much? May be they should.

More reading: Complete list of Excel shortcuts

]]>

**Start your bar (or column) charts from zero.**

To illustrate why you should do this, let me share a personal example.

Over the weekend, *the *Jon Peltier visited Wellington. He is staying with Jeff (who occasionally guest blogs on Chandoo.org). On Sunday, we all decided to hike up a small mountain near my house for a leisurely family picnic.

While on the top of the mountain, Jo (my wife) took a few pics of us three Excel geeks. As we were standing on a sloping mountain face this is how the pictures look:

Looking at the picture on left, you would confidently say that I am way shorter than other two. But picture on right tells a different story.

Of course, the reality is somewhere between two pictures. It is difficult to conclude who is tall, who is short just looking at the pics simply because the *baseline is sloping. *

**But we can’t have sloping baselines in Excel charts**

You are right we can’t. But we can still confuse people with an arbitrary axis start. Like below:

**The fix? always start your axis at zero for bar (or column) charts:**

Simple. Set the axis start point to zero (Select axis, press Ctrl+1, and from Axis options set minimum to 0).

So there you go. The shortest Excel charting tip ever, but still stands tall when it comes to telling great stories.

**More charting principles:**

If you are in the mood for some more charting theory and elegant methods, check out below links.

]]>**How to show selective sub-totals in Pivot Tables**

First instinct suggests that using Design ribbon > Sub-totals we can tell pivot table how we want the sub-totals.But this is like a master switch. It will turn off or on all sub-totals in the report. What we need is sub-totals only at one level of the report (in this case, sub-totals by department, but not by month).

The answer is simple.

- Click on any month label. This will select all months in the row label area.
- Right click > Field settings (you can also access this from Analyze Ribbon > Field Settings)
- In the “Subtotals & Filters” tab, choose “None”
- You are done.

Happy Pivoting. I am off to a short spin on my cycle before heading to work.

This is because **you are hiring a person for new temp role even before their current one ended**. See below picture.

So how to avoid making such hiring boo-boos.

Simple, using Excel of course.

There are a few ways to handle this problem.

- Using formulas to check if a person is hired twice in the same period
- Using conditional formatting to highlight such hires
- Using data validation to prevent such data entry

I made a video covering all these methods in detail. Check it out below or on Chandoo.org YouTube channel.

**Click here to download the workbook** showcased in the video. Play with various dates & names to test formulas, CF and data validation.

Learning few simple Excel best practices and techniques can save you a lot of time & money. So why wait, check out below links and become awesome in Excel.

- Advanced Excel skills & resources – learn the right way
- What is Conditional Formatting and how to use it? [Video]
- 5 tips to become conditional formatting rock star
- Introduction to SUMIFS
- MAX IF formula

While you are at this, subscribe to Chandoo.org YouTube channel. I have been uploading videos once a month. While this is not exactly a staggering pace, you are sure to be a rockstar at work if you just watch all the previous vids and stay tuned for more. **Check it out**.

- Introduction to Excel tables
- How to use structured referencing
- Tables and Relationships in Excel
- Using lookups and other formulas with Excel tables
- Simple way to get absolute references in Tables
- Customizing table styles for awesome usability

**While tables are super helpful, they do come with some limitations.** Today let’s examine one such unique problem and learn about an elegant solution.

Imagine you are the machine supervisor at Mighty Machine City Inc. Although your machines are mighty, sometimes they do fail. To keep track of which machines are under repair, you maintain a *repair log *in Excel. Since you heard Tables are mighty, you thought,

‘*Gee whiz, I might as well use tables to maintain the repair log. Chandoo says tables are sweet’*

So, your Repair log looks like this:

After a few days of tracking the repairs, you wanted to know if same machines are failing successively. For example, in above picture, you notice that MACH-0038 failed twice in a row starting with 11th of March. Same goes for few other rows.

You are the kind of person who frowns upon manually highlighting yellow color in cells to flag such successive failures. So you want to write a formula.

So you add a new column called **Same?** and want to fill it up with a simple relative reference formula to check with Machine in row 1 matches machine in row 2.

Here is the formula you used:

=[@[Machine ID]] = B6

*Note: *Your table starts with Row 5.

Excel automatically filled down the formula for all rows of the table, *because tables are awesome like that.*

You whistled your way to home that night.

Next day morning, as usual *Homer messed up something *and you had a new repair to log. So you went to the bottom of *fail *table and inserted a new row to add the failure details.

And you notice something unusual.

**The formula for Same? column is WRONG!!!**

As soon as you inserted a new row, Excel adjusted last row’s formula to something silly.

**Before:**Let’s say the last row formula reads =[@[Machine ID]]=B20**After:**The last but one row (as you now have an empty row)’s formula reads =[@[Machine ID]]=**B21**

Now that is clearly wrong!

**What is going on here?**

Your relative referencing worked ok, until the last row. At this stage, Excel *understood *the formula as **Current row value = value in first cell below table**

The part in green is what caused trouble. As soon as you add a new row to your table, *fist cell below table *is moved down. So Excel adjusted that reference alone.

**How to fix this problem?**

The usual method to fix this:

- Insert as many rows as you need and complete entering / pasting all data.
- Select the formula in very first cell.
- Fill it down all the way (you can double click on the bottom right corner of the cell)

**But that is soooo not awesome.**

You are right. This method is manual and error prone. It is the opposite of awesome.

**Problems when you delete too:** In fact, if you ever delete a row from your table, the formulas further down would show #REF! errors. So this method is not very effective in real life.

Instead of using cell address based references, like B6, if you use pure structured references, then Excel will automatically adjust them as your table grows or shrinks.

But how?

Simple, we can use OFFSET function along with @ references.

To get next machine ID, you can use

=OFFSET([@[Machine ID]],1,0)

So, to check if same machine failed twice in a row, use

=[@[Machine ID]]=OFFSET([@[Machine ID]],1,0)

As this uses no cell references, whenever you add / change / remove table rows, Excel automatically scales the formula.

**But I heard OFFSET is volatile / dangerous / RDX / %#$&@#?**

Unless your table has a 200k+ rows or you plan to set up 100s of columns like this, don’t bother. for small, day to day tables, there is no change in performance. If you really hate OFFSET, try talking about it during your next therapy session. Jokes aside, you can also use a longer INDEX based formula to get similar result, but that is semi-volatile too.

Here is one such INDEX based formula.

=INDEX([@[Machine ID]]:INDEX([Machine ID],COUNTA([Machine ID])), 2)

It sure is a mouthful. You can shorten it by using a named formula for INDEX([Machine ID],COUNTA([Machine ID])) portion or the whole thing. Again, I wouldn’t recommend the INDEX based approach over OFFSET for smaller data sets. For larger datasets, see if you can fix the problem at source (for example, modifying your SQL to get offset values in a separate column) or using Power Query to mash the data (more on this in a next post).

So there you go, an elegant and simple way to deal with the relative reference problem in tables.

You can use this approach to generate running numbers (1,2,3…) in a table column that grow / change / shrink based on your table. This can be very useful in many scenarios.

To get running numbers in a table column, just use:

=ROWS(fail[[#Headers],[Machine ID]]:[@[Machine ID]])-1

The pattern that you can use in any table goes like this:

=ROWS(Table_Name[[#Headers],[Col 1]]:[@[Col 1]])-1

You can then change the OFFSET based relative ref to INDEX like below.

=INDEX([Machine ID],[@Running]+1)

This method is 100% non-volatile, but does return #REF! error for the last row. So use it with IFERROR when nesting in other formulas.

**Click here to download an example workbook** showcasing all these techniques. Use the extra data to paste and test various methods.

The handful times when I had to use relative refs in a table, I resorted to cell refs (like B6 above). But this created too much headache further down. So I switched to OFFSET / INDEX approaches.

**What about you? **How do you write relative references in tables? Please share your stories & struggles in the comments section.

If you are relatively free and want some relaxed reading then check out below related reference links.

- An intro to Excel relative references, structured references
- INDEX formula, OFFSET formula, ROWS formula

Happy learning.

]]>