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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
jimmyhua
Helper I
Helper I

use List.Generate to create a conditional index gave me Expression.Error

I tried to create a conditional index for another list I created. here is the code I wrote and error I got.  The first list is to create a position indicator where the index can began. The first one worked. and the second one gave the error.

=[
Splitposition= List.PositionOf(List.Transform(#"Filtered Rows"[Vendor Subline Num], each _ =1), true, Occurrence.All),

Conditionalindex = List.Generate(()=>0, each _ >= Splitposition, each _ +1)

]

 

Expression.Error: We cannot apply operator < to types List and Number.
Details:
Operator=<
Left=[List]
Right=0

1 ACCEPTED SOLUTION

use the below formula

let
    Source = {1,1,2,3,1,2,1,2,3,4,5,1,2,3,1,1,2},
    Custom1 = List.Transform(List.Positions(Source), each if Source{_}=1 then _+1 else null)
in
    Custom1

result in 

 

Omid_Motamedise_0-1729633200821.png

 

 

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h

View solution in original post

11 REPLIES 11
Omid_Motamedise
Super User
Super User

the result of Splitposition is a list and
in this part

_ >= Splitposition

 

you can not compare a number (_) with a list (Splitposition).

 

you can replace it by _ >= Splitposition{0}

but if you explain the purpose of your function I can help you more

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h
lbendlin
Super User
Super User

Occurrence.All will create a list.

yes.  i do want a list because there are multiple 1s in the first list.  want i want to do is first to find the positions of the 1s then create fill in nulls in between each position so i can fill down and group them together.  is there a way to do it?

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information. Do not include anything that is unrelated to the issue or question.

Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

here is sample list1, which represents a column in a table that I need to group. each 1 starts a new group.  I use List.PositionOf to find out the positions where each group starts.  Then I want to fill in nulls and use fill down to fill the spaces.  I will use the new index column to group the entire table.
{1,1,2,3,1,2,1,2,3,4,5,1,2,3,1,1,2}

Hi @jimmyhua 

"here is sample list1, which represents a column in a table that I need to group. each 1 starts a new group."

 

You can use Table.Group directly

 

= Table.Group(
YourSource,
{"YourColumn"},
{{"Data", each _}},
GroupKind.Local,
(x,y) => Byte.From(y[YourColumn]=1)
)

 Stéphane

wow.  i have never used Table.Group function.  this is eye opening for me.  Thanks a lot.

Please show the expected outcome based on the sample data you provided.

I would like to be able to create a list2 like this based on list1

{1,2,null,null,5,null,7,null,null,null,null,12,null,null,15,16,null}

use the below formula

let
    Source = {1,1,2,3,1,2,1,2,3,4,5,1,2,3,1,1,2},
    Custom1 = List.Transform(List.Positions(Source), each if Source{_}=1 then _+1 else null)
in
    Custom1

result in 

 

Omid_Motamedise_0-1729633200821.png

 

 

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h

 

let
    list1 = {1,1,2,3,1,2,1,2,3,4,5,1,2,3,1,1,2},
    list2 = List.Transform(List.Zip({list1,List.Positions(list1)}), each if _{0}=1 then _{1}+1 else null)
in
    list2

 



Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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