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

Don'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.

Reply
Sam88
Frequent Visitor

Problem with M function Text.NewGUID()

Hi!

we would like to assign a different GUID for each Row in a Query.

I've tried the function Text.NewGUID() but there are some strange behaviours.

 

I noticed that:

-  in Query Editor it's mandatory to put the column with the GUID as last after an index;

- if I merge or append the query with the ID with another one the system set the same GUID for every row;

- when the query it's applied the system set the same GUID for every row as in Report as in Data View.

 

Have someone experienced the same issue?

 

thanks,

have a nice day

 

Samuele

 

1 ACCEPTED SOLUTION
MarcelBeug
Community Champion
Community Champion

I don't fully understand your issues, but I recognize the duplicate GUIDs.

 

It must have something to do with lazy evaluation (Power Query code is evaluated only if absolutely required; in this case it looks like one time evaluation of Text.NewGuid is regarded sufficient to generate GUID's for multiple rows, which is - of course - wrong).

 

Maybe somebody will come up with a better solution, but a working workaround is to create the new Guid as a nested table and take the value of Column1, row 0:

 

let
    Source = #table(type table[ID = Int64.Type],List.Zip({{1..10}})),
    #"Added Custom" = Table.AddColumn(Source, "GUID", each #table(1,{{Text.NewGuid()}})[Column1]{0}, type text)
in
    #"Added Custom"

 

Edit: beware that new GUID's will be created with every refresh of the query. 

Specializing in Power Query Formula Language (M)

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

Hi @Sam88,

 

It is an known issue which consulted form product team, you can refer to below link to know more about this:

Problem with Text.NewGUID() M Language

 

BTW, if you only input Text.NewGUID() to custom column formula, it seem return the static value, but if you add some calculation to this query, it will return the dynamic value.

8.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
MarcelBeug
Community Champion
Community Champion

I don't fully understand your issues, but I recognize the duplicate GUIDs.

 

It must have something to do with lazy evaluation (Power Query code is evaluated only if absolutely required; in this case it looks like one time evaluation of Text.NewGuid is regarded sufficient to generate GUID's for multiple rows, which is - of course - wrong).

 

Maybe somebody will come up with a better solution, but a working workaround is to create the new Guid as a nested table and take the value of Column1, row 0:

 

let
    Source = #table(type table[ID = Int64.Type],List.Zip({{1..10}})),
    #"Added Custom" = Table.AddColumn(Source, "GUID", each #table(1,{{Text.NewGuid()}})[Column1]{0}, type text)
in
    #"Added Custom"

 

Edit: beware that new GUID's will be created with every refresh of the query. 

Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.