• 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

Very complex conditional combined query.|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Very complex conditional combined query.|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 QueryVery complex conditional combined …
sp_PrintTopic sp_TopicIcon
Very complex conditional combined query.
Avatar
Faiber Rodriguez

New Member
Members
Level 0
Forum Posts: 2
Member Since:
November 21, 2018
sp_UserOfflineSmall Offline
1
November 21, 2018 - 6:28 am
sp_Permalink sp_Print

Hi, i need the following:

I have a column named "Account" and another one named "Company" on my table and i also have a file with a table that shows the accounting format for that Company, two columns named "Account" that is a code number and "Name of the account". So i need to join the info from column "Account" with the additional file, in order to show the name of the account, right now its simple, issue comes when i deal with different companies, i have one external file for each company coding system (Each company has different accounting system), so this nested join depends on the value on company column.

Account (Number) Company (Name) Nested join (Name of the account on each company)

505123 ABAD General expenses(Info brought from additional file (one file for each company))

505123 DYNAMIC Other Incomes (Info brought from additional file with the company codes)

That is the desirable result, cause account numbers, doesnt mean the same in all companies, so i want to automatize this, right now only solution i found its to change manually in the code editor the query name of each accountable system and do the job separately by companies.

The external file data structure its simple: This should be the one for company ABAD.

Acount (Number) Name of the account (String)

505123 General Expenses

So i need to evaluate column company, depending on this, go to that file and do the nested join, thing is i cant get the origin of external file a variable and use it in the advanced editor. i tried couple solutions but no success. Anyone can help me?

Would be nice to learn how to solve this.

Avatar
Faiber Rodriguez

New Member
Members
Level 0
Forum Posts: 2
Member Since:
November 21, 2018
sp_UserOfflineSmall Offline
2
November 21, 2018 - 6:41 am
sp_Permalink sp_Print

Actual code that it works statically, i have to change manually the PUC_XXX, i want to make this query name variable, in order that depends on the value in [Empresa] field.

 #"Consultas combinadas" = Table.NestedJoin(#"Acomodar jerarquía cuentas",{"CUENTA"},PUC_DYNAMIC ,"Consulta (2)",JoinKind.LeftOuter),

 

Desired code, should be something like this:

 #"Consultas combinadas" = Table.NestedJoin(#"Acomodar jerarquía cuentas",{"CUENTA"},if [Empresa]="DYNAMIC" then PUC_DYNAMIC else if [Empresa]="ABAD" then PUC_ABAD else PUC_TT,{"CUENTA"},"Consulta (2)",JoinKind.LeftOuter),

but this code doesnt work, it says "unknown identifier".

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1810
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
3
November 23, 2018 - 3:39 pm
sp_Permalink sp_Print

Hi Faiber,

You should try the Expression.Evaluate function to call different queries:

QName="Query1",

 #"Consultas combinadas" = Table.NestedJoin(#"Acomodar jerarquía cuentas",{"CUENTA"},Expression.Evaluate(QueryName,[QueryName=QName]),{"CUENTA"},"Consulta (2)",JoinKind.LeftOuter),

Using Query name in Evaluate returns that query and it will be seen as a table or whatever that query results into.

.NestedJoin is not looking at specific rows context, it just takes 2 tables and joins them, you cannot use the Empressa column inside this function to loop through rows, you need an iterator for that.

I think you have to create parameters for each query name, by filtering the table based on Empressa column :

TblDynamic = Table.SelectRows(#"Acomodar jerarquía cuentas", each ([Empressa] = "DYNAMIC")) ,

TblABAD = Table.SelectRows(#"Acomodar jerarquía cuentas", each ([Empressa] = "ABAD")) ,

 JoinDynamic = Table.NestedJoin(#"Acomodar jerarquía cuentas",{"CUENTA"},TblDynamic,{"CUENTA"},"Consulta (2)",JoinKind.LeftOuter),

JoinABAD = Table.NestedJoin(#"Acomodar jerarquía cuentas",{"CUENTA"},TblABAD,{"CUENTA"},"Consulta (2)",JoinKind.LeftOuter),

Combined=Table.Combine(JoinDynamic,JoinABAD)

 

Or, you can do that in 1 step:

Combined=Table.Combine(Table.NestedJoin(#"Acomodar jerarquía cuentas",{"CUENTA"},TblDynamic,{"CUENTA"},"Consulta (2)",JoinKind.LeftOuter)    ,                                     Table.NestedJoin(#"Acomodar jerarquía cuentas",{"CUENTA"},TblABAD,{"CUENTA"},"Consulta (2)",JoinKind.LeftOuter))

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Kim Knox, Bhuwan Devkota
Guest(s) 8
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 871
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
Jessica Stewart: 204
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Bhuwan Devkota
Kathryn Patton
Maria Conatser
Jefferson Granemann
Glen Coulthard
Nikki Fox
Rachele Dickie
Raj Mattoo
Mark Luke
terimeri dooriyan
Forum Stats:
Groups: 3
Forums: 24
Topics: 6221
Posts: 27285

 

Member Stats:
Guest Posters: 49
Members: 31909
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.