Power Query Add / Insert Row on condition

jdellasala

Well-known Member
Joined
Dec 11, 2020
Messages
755
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
There's a web site (Market Holidays for United States for 2022) that has a small table of the list of Market Holidays. Long story short, I was able to pull in all the tables from 1900 to 2100 using a Power Query function. In doing that I discovered that 56 years (including 2017) are missing the Market being closed for New Year's Day on January 2nd when the 1st falls on a Saturday or Sunday.

The table is simply 2 rows - Date and Holiday. The question is how can add a row in the function if the Holiday "New Year's Day" doesn't exist in the 2nd column, giving the first (Date) column the value of the first Tuesday in January (it can be either the 2nd or the 3rd depending on when the 1st was), and "New Year's Day" to the second (Holiday) column?

Thanks
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
OK, I should have waited a bit longer. I figured out how to fix the problem.

I generated another table of years from 1900 to 2100, created January 1st for all of the rows by adding a custom column, added a "Day of Week" column, added another column for "Holiday" (with a value of "New Year's Day Observed") if the Day of Week equaled 0 or 6, got rid of the blank rows in that column, and finally appended that table to the one pulled in from the Web which was then sorted by date.

It's funny how one (me!) can be completely oblivious to an answer staring you in the face! I had already generated one table with a column of values from 1900 to 2100, but was trying to figure out how to do it in THAT table instead of just generating a table with the needed data.

Oh yeah, the beauty of Power Query - I emailed the site about the issue, and if they fix it my table will end up with two records for every New Year's Day that falls on a Saturday or Sunday. But if that does happen and I need to fix it (because it bothers me!), I can just delete the "Appended Query" step in the full table! It's a beautiful thing!!
 
Upvote 0
Solution

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top