Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
I have this bit of code:
let Source = FlattenHierarchy(paramAccount_title, paramAccount_id, paramAccount_parentId, paramAccount_display) in Source
And this gets called by a function called TestFunction.
Then after this I have another bit of code that:
let Source = datamapping, #"Filtered Rows1" = Table.SelectRows(Source, each ([module] = "interimreporting")), #"Filtered Rows2" = Table.SelectRows(#"Filtered Rows1", each [table] = "dimAccount"), #"Invoked Custom Function" = Table.AddColumn(#"Filtered Rows2", "TestFunction", each accountHierarchy_Function([hierarchyName], [id], [parentId], [displayField])), accountHierarchy = #"Invoked Custom Function"{0}[TestFunction] in accountHierarchy
Is there any way I can combine the first bit of code into the last one, and by-pass the intemdiary step. Note that what the last bit of code is doing, in the "Invoke Custom Function" step, is that its getting the input for TestFunction from the columns in the tables from the previous step. In doing so it's doing an Each to iterate through all rows in the table.
However I can safely assume that the table only has 1 row, and therefore instead of doing the Each I just want to feed these same column values into:
FlattenHierarchy(paramAccount_title, paramAccount_id, paramAccount_parentId, paramAccount_display)
Solved! Go to Solution.
I think you should be able to simplify the M code down to the following, just using #"Filtered Rows2"{0} to reference the first row from the second Table.SelectRows() call and then just call the FlattenHierarchy function directly. I would not expect too much change in performance, but it will reduce the number of queries in your model.
let Source = datamapping, #"Filtered Rows1" = Table.SelectRows(Source, each ([module] = "interimreporting")), #"Filtered Rows2" = Table.SelectRows(#"Filtered Rows1", each [table] = "dimAccount"), accountHierarchy = FlattenHierarchy(#"Filtered Rows2"{0}[hierarchyName], #"Filtered Rows2"{0}[id], #"Filtered Rows2"{0}[parentId], #"Filtered Rows2"{0}[displayField]) in accountHierarchy
I think you should be able to simplify the M code down to the following, just using #"Filtered Rows2"{0} to reference the first row from the second Table.SelectRows() call and then just call the FlattenHierarchy function directly. I would not expect too much change in performance, but it will reduce the number of queries in your model.
let Source = datamapping, #"Filtered Rows1" = Table.SelectRows(Source, each ([module] = "interimreporting")), #"Filtered Rows2" = Table.SelectRows(#"Filtered Rows1", each [table] = "dimAccount"), accountHierarchy = FlattenHierarchy(#"Filtered Rows2"{0}[hierarchyName], #"Filtered Rows2"{0}[id], #"Filtered Rows2"{0}[parentId], #"Filtered Rows2"{0}[displayField]) in accountHierarchy
Thanks - this greatly simplified my code!
User | Count |
---|---|
116 | |
73 | |
60 | |
48 | |
48 |
User | Count |
---|---|
171 | |
122 | |
60 | |
59 | |
56 |