Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
houghtonap
Frequent Visitor

Function reference value of #shared is not the same as the actual function reference

I have run into an oddity that I cannot explain and hope someone in the community can explain the situation. My Power BI Desktop has the following items:

 

// SimpleFunction
let
    result = ( ) => [ a = 1, b = 2, c = 3 ]
in
    result

// ShowMyStuff
let
    result = Table.SelectRows( Record.ToTable( #shared ), each not Text.Contains( [Name], "." ) )
in
    result

// FindSimpleFunction
let
    result = Table.SelectRows( ShowMyStuff, each [Value] = SimpleFunction )
in
    result

// DoesReferenceMatch
let
    result = #shared[SimpleFunction] = SimpleFunction
in
    result

// ExecuteSharedReference
let
    result = (#shared[SimpleFunction])( )
in
    result

// InvokeSimpleFunction
let
    result = SimpleFunction()
in
    result

 

  1. The query FindSimpleFunction returns an empty table.
  2. The query DoesReferenceMatch returns false.
  3. The query ExecuteSharedReference returns the same as InvokeSimpleFunction.

What I cannot explain, after searching the docs and googling, is why DoesReferenceMatch returns false, implying that the reference provided by #shared is not the same reference as SimpleFunction. However, when invoking the #shared reference it returns the same result as invoking SimpleFunction. It seems to me that what is returned by #shared is some sort of proxy for SimpleFunction.

 

Can someone point me to the docs or an article that explains this behavior of #shared? It would be handy, if the reference were the same, then a query like FindSimpleFunction would be able to return the textual name for a given reference value.

 

1 ACCEPTED SOLUTION

@ImkeF, that is an interesting observation about what #shared returns. In doing further research, I found that #sections can also be used and it does return the original function value:

#sections[Section1][SimpleFunction] = SimpleFunction

 This brings up another question, why would Microsoft make the return values for #shared and #sections different!? Regardless, there are now two viable solutions for retrieving the textual name for a reference value and a possible explaination why #shared and #sections return differnet values. Thanks for sharing your observation.

View solution in original post

3 REPLIES 3
ImkeF
Super User
Super User

Hi @houghtonap ,
I would be very carefull with that, as what you see in the query editor might not be the same than what is loaded into the data model or refreshed in the service.
You might want to test that thoroughly before using for actual work.
BTW: In a different file, I couldn't replicate the metadata behaviour. So if at all, I'd go for the Section function.
Very much agree that these functions should behave better 🙂

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

ImkeF
Super User
Super User

Hi @houghtonap ,
don't know if this is mentioned in the docs, but #shared handles the metadata differently, basically returning the metadata first.
So this will return true:

#shared[SimpleFunction] = Value.Metadata(SimpleFunction)



Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

@ImkeF, that is an interesting observation about what #shared returns. In doing further research, I found that #sections can also be used and it does return the original function value:

#sections[Section1][SimpleFunction] = SimpleFunction

 This brings up another question, why would Microsoft make the return values for #shared and #sections different!? Regardless, there are now two viable solutions for retrieving the textual name for a reference value and a possible explaination why #shared and #sections return differnet values. Thanks for sharing your observation.

Helpful resources

Announcements
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors
Top Kudoed Authors