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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Dicken
Responsive Resident
Responsive Resident

Lists of text and number types

Hi, 
can someoen explain this ; if you have a llsit 

 = let alist = 
 {1,"a","b",3,3} in alist


you get a list of text and number alignment's left and right , but if you have a nested list 

= let alist = 
{ {"a",1} , {"b",2} , {"c", 3}} 
in alist


then all is left or text aligned,   any ideas as to what happens between one and nested to cause this? 

Richard

3 ACCEPTED SOLUTIONS
AmiraBedh
Super User
Super User

Hello Dicken !

What you’re seeing is just the PQ UI is reacting to types.

{1,"a","b",3,3} each element is a scalar value and PQ knows the type of each item and the preview grid aligns them accordingly: numbers right, text left.

 

{{"a",1},{"b",2},{"c",3}} here each element of the outer list is itself a list and in the preview, PQ doesn’t look inside those inner lists when they decide alignment so it just shows values which are aligned like text. If you expand them, the columns start as type any which also aligns left until you set a numeric type.

 

So if you want the proper numeric right alignment, turn that nested list into a real table and set types:

let
    alist   = { {"a",1}, {"b",2}, {"c",3} },
    asTable = Table.FromRows(alist, {"Letter","Number"}),
    typed   = Table.TransformColumnTypes(asTable, {{"Letter", type text}, {"Number", Int64.Type}})
in
    typed

 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

View solution in original post

vojtechsima
Super User
Super User

Hey, @Dicken ,

Lists are lazily evaluated. On demand, Power Query evaluates the top-level and structure. If you would nest the same list as in your first example:

let alist = {
 {1,"a","b",3,3}} in alist

You'll get the same behaviour, everything as text:

vojtechsima_0-1762097304082.png

Once you go inside and inspect each value separately, you'll see the types evaluated precisely:

vojtechsima_1-1762097336024.png

 

I general, Power Query wants to be as lazy as possible, if it doesn'T have to evaluate something, it won'T, so unless you call the concrete item in a list (for example by displaying the lowest nested items), it won't do the types as you would expect.

 

More on evaluation in my blog:

https://www.vojtechsima.com/post/how-power-query-m-evaluates-your-queries-and-why-the-performance-ge...

View solution in original post

@Dicken 
Yeah, basically. Until you evaluate a specific item from the nested list, you MAY not get the type. The may is important, as it's kinda specific to lists, as you can see it does differentiate between the types, and for exampl,e tables preview will show you the correct representation immediately.

See example:

= {
#table({"col1", "col2", "col3"}, {{"a", "b", 1}}), {1,2,3, "1", "a"}
}

 

vojtechsima_0-1762099569881.pngvojtechsima_1-1762099573412.png

 

View solution in original post

5 REPLIES 5
vojtechsima
Super User
Super User

Hey, @Dicken ,

Lists are lazily evaluated. On demand, Power Query evaluates the top-level and structure. If you would nest the same list as in your first example:

let alist = {
 {1,"a","b",3,3}} in alist

You'll get the same behaviour, everything as text:

vojtechsima_0-1762097304082.png

Once you go inside and inspect each value separately, you'll see the types evaluated precisely:

vojtechsima_1-1762097336024.png

 

I general, Power Query wants to be as lazy as possible, if it doesn'T have to evaluate something, it won'T, so unless you call the concrete item in a list (for example by displaying the lowest nested items), it won't do the types as you would expect.

 

More on evaluation in my blog:

https://www.vojtechsima.com/post/how-power-query-m-evaluates-your-queries-and-why-the-performance-ge...

Thanks to both, I have a look at the blog, so let me see if i get this,   as 
lists are nested,     {  {} }   the first level is a list not a number which affects subsequent values ? 

@Dicken 
Yeah, basically. Until you evaluate a specific item from the nested list, you MAY not get the type. The may is important, as it's kinda specific to lists, as you can see it does differentiate between the types, and for exampl,e tables preview will show you the correct representation immediately.

See example:

= {
#table({"col1", "col2", "col3"}, {{"a", "b", 1}}), {1,2,3, "1", "a"}
}

 

vojtechsima_0-1762099569881.pngvojtechsima_1-1762099573412.png

 

thanks for the help.

AmiraBedh
Super User
Super User

Hello Dicken !

What you’re seeing is just the PQ UI is reacting to types.

{1,"a","b",3,3} each element is a scalar value and PQ knows the type of each item and the preview grid aligns them accordingly: numbers right, text left.

 

{{"a",1},{"b",2},{"c",3}} here each element of the outer list is itself a list and in the preview, PQ doesn’t look inside those inner lists when they decide alignment so it just shows values which are aligned like text. If you expand them, the columns start as type any which also aligns left until you set a numeric type.

 

So if you want the proper numeric right alignment, turn that nested list into a real table and set types:

let
    alist   = { {"a",1}, {"b",2}, {"c",3} },
    asTable = Table.FromRows(alist, {"Letter","Number"}),
    typed   = Table.TransformColumnTypes(asTable, {{"Letter", type text}, {"Number", Int64.Type}})
in
    typed

 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors