• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Replace Null Values in Merged Table using lookup logic|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Replace Null Values in Merged Table using lookup logic|Power Query|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumPower QueryReplace Null Values in Merged Table…
sp_PrintTopic sp_TopicIcon
Replace Null Values in Merged Table using lookup logic
Avatar
Viktor Hoogstoel

New Member
Members
Level 0
Forum Posts: 2
Member Since:
May 5, 2020
sp_UserOfflineSmall Offline
1
November 5, 2021 - 2:51 am
sp_Permalink sp_Print sp_EditHistory

Hi all,

Power Query question here. In my merged query table attached in sheet 3, the "Weather" and "Weather Estimate" columns are sometimes null. I am trying to include some logic to those columns that if the column is null, to use the "Use Weather From" column to match a Site ID for the same day and use the Weather and Weather Estimate data from that site. 

For example, on 10/2/21, Site 8 (site ID 50050) has null data for weather and weather estimate, so I'd want to take weather data from site 50078 for 10/2 for that day. In this case the answer would be 4939 and 4483. 

I believe I either need to create a new custom column, or use the advanced editor under power query, or likely a combination of both but I think all would require BI coding that is lost on me. 

Hope someone can help out! This would be so cool if it works!

Viktor 

sp_AnswersTopicSeeAnswer See Answer
Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1514
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
2
November 5, 2021 - 5:22 pm
sp_Permalink sp_Print

Hi Viktor,

Attached is a file that fills in the blanks as requested.

There are a few issues though as there are some Site ID's where their Use Weather From is their own ID.  SO if the Weather or Weather Estimate is null for those ID's, there's nothing to replace it with.

I've created a query called Problems that lists where this occurs.

You also have errors (Site Name is N/A) in your Production Data which are causing errors in the final query.  If you fix the source the query errors will disappear.

Regards

Phil

sp_AnswersTopicAnswer
Answers Post
Avatar
Viktor Hoogstoel

New Member
Members
Level 0
Forum Posts: 2
Member Since:
May 5, 2020
sp_UserOfflineSmall Offline
3
November 6, 2021 - 7:19 am
sp_Permalink sp_Print

Phil,

Really appreciate you getting back to me. I tried to re-create your work on my own, to ensure that I am learning the process. I think I understand what you mean with the errors, as my query results in errors and the formulas won't work. I am not sure how you overcame that, as I don't see an applied step of removing any errors. So I can't reproduce exactly as you have done.

In terms of the errors I think it's throwing, I suppose I should have given more detail. It's possible for the sensor that is producing the data to go down, so null values would be expected in that case. So, if the Site ID and Use Weather From columns match, and the value is still null, then null is fine. 

It looks like your file is already doing that, which is great. 

I think i'm close, but let me know if I went wrong somewhere. 

The steps I did were:

1. Opened up query editor and added 3 custom columns, kept your source code (thank you!)

2. Got an error with Weather_Form, so added that as a query and then custom1 formula was happy 

3. Applied columns but seeing errors in each when I hover over row 0 on the query editor. My custom columns are just a mirror of the originals.

 

Thank you!

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1514
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
4
November 8, 2021 - 1:28 pm
sp_Permalink sp_Print

Hi Viktor,

The errors are caused because you have rows in your Production Data where the Site Name is a #N/A error, for example Row 1831 to Row 1861.  It's not related to any nulls.

In the Prod query, when the queries are merged, they merge based on matching Site ID.  As you have rows where there are no site ID's - they are the #N/A errors - these rows do not appear in the merged table.

I think the code in this step may be confusing as I've named a table and a variable very similarly - WeatherFrom and Weather_From.  So I've changed those to Weather_From_Table and WeatherFromID

= Table.AddColumn(#"Removed Columns", "Custom.1", each let

WeatherFromID = [Info.Use Weather From],
TS = [Timestamp]

in

if [Weather] is null or [Weather Estimate] is null then Table.SelectRows(Weather_From_Table, each [Site ID] = WeatherFromID and [Timestamp] = TS)

else [Weather])

 

After the queries are merged and the Table in the Info column is expanded you need to tidy up a little by removing the old Weather and Weather Estimate columns, and a couple of others.

See attached file for code.

Regards

Phil

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: MohamedGadAllah, Jeff Krueger, RAMEZ ATTAR, Kylara Papenfuss, Nada Perovic
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
John Chisholm
vexokeb sdfg
John Jack
Malcolm Toy
Ray-Yu Yang
George Shihadeh
Naomi Rumble
Uwe von Gostomski
Jonathan Jones
drsven
Forum Stats:
Groups: 3
Forums: 24
Topics: 6212
Posts: 27236

 

Member Stats:
Guest Posters: 49
Members: 31889
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.