cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
igaca
Helper III
Helper III

M Function to return a list of all queries residing in Power Query?

Is there such a thing?  I've looked through the msft library with no luck (also via "=#shared" in PQ)

 

I need a dynamic and automated way to generate this list to pass off as a parameter to another function.

Let me know if you have any suggestions.

 

Thanks!

 

Igor

1 ACCEPTED SOLUTION
hohlick
MVP

Check =#sections[Section1]
it is a record, you can get its field names then.
Beware of recursion!
Maxim Zelensky
excel-inside.pro

View solution in original post

7 REPLIES 7
hohlick
MVP

Check =#sections[Section1]
it is a record, you can get its field names then.
Beware of recursion!
Maxim Zelensky
excel-inside.pro

View solution in original post

Oustanding Maxim; pretty sure this will do!

I am wanting to create a query that will automatically scan through (any) model tables/queries, ID "date" / "datetime" fields, determine MIN and MAX values and then feed those as parameter inputs into a query function that generates a dimCalendar table (FNdimCalendar) automatically.  Step one is to ID the tables which can then be passed off to something like Table.Schema function etc.  You just paved the initial portion of the path.

 

Side questions:

 

1) your comment to "Beware of recursion" - can you please elaborate?

 

2) Are you aware of any command etc. that would allow the query grouping structure to be accessed as well?  Below excerpts are those of a poor example (essentially testing model) - I am referring to "Sources" and "Other Queries".

Sections 01.png

 

 

Thank you again for the input!

 

Igor

HI Igor
Nice idea, I think. I previously made function to create such calendar from one table, but not from all
Sometimes when I used this #sections trick, it didn't work inside the queries... do not sure what is the reason.
Concerning your questions:
1) you should filter out your query Pay_App_Data, for example. Sections shows you all queries and functions and parameters etc., including this query itself. You should find a way to select only tables there (you can filter it by type, but it is a little bit tricky)
2) don't sure there is a way to reach it by M. I think it is only UI, and not implemented in M
Maxim Zelensky
excel-inside.pro

1) That is precisely what I had in mind.  I am not seeing why it should be tricky but let me dig into it and I am sure I will find something else to quiz you on 🙂

2) 10-4.  As part of my research, I reached out to some Microsoft engineers via email.  Should I actually get a reply, I will be sure to ask this questions as well and will let you know what they say.

 

Happy holidays!

Anonymous
Not applicable

Awesome question, and I think I have a solution to only keeping the tables.  Essentially, a try statement that attempts to count the number of columns in a table (all tables will have at least 0).  -1 is thrown in case of an error.  Then just keep the rows with a value >-1

 

 

 

let
    Source = #sections,
    Section1 = Source[Section1],
    #"Converted to Table" = Record.ToTable(Section1),
    #"Add TableTest" = Table.AddColumn(#"Converted to Table", "TableTest", each try Table.ColumnCount([Value]) otherwise -1, Int64.Type),
    #"Filtered Rows" = Table.SelectRows(#"Add TableTest", each [TableTest] > -1)
in
    #"Filtered Rows"

HI Chris
It could be done a little bit easier after converting Section1 to table:

Table.SelectRows(Table, each [Value] is table)

IS - operator for type comparison
Maxim Zelensky
excel-inside.pro
Anonymous
Not applicable

Never knew about "is".  That's an awesome solution!

Helpful resources

Announcements
PBI_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Get Ready for Power BI Dev Camp

Microsoft named a Leader in The Forrester Wave

Microsoft received the highest score of any vendor in both the strategy and current offering categories.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Top Solution Authors
Top Kudoed Authors