cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Tapesh
Post Prodigy
Post Prodigy

How to reset the sequnce number to 0 when item in then collection is blank?

Hi all Experts, 


I have been trying to the sequence starting from and increase to the number of items present in the collection/gallery. 
However, I have to now modify a bit by using conditional statement, where is the unitname is blank start the sequence from 0 again and increase to the corresponding records and so on. 


The code on my gallery items is as below:

 

 

ForAll(
Sequence(CountRows(ExportData),0),

{
myRecord: Last(FirstN( Sort (ExportData , ID,Ascending ),Value +1)),
rowNumber: Value
}
)

 

 

The result I am getting is as below: 

But I want to start the number from 0 again if  the below filed is blank.

 

 

ThisItem.myRecord.'Unit Name'.Value

 

 

 

In the below example the number should for example start from 0 again where the Name is shown as "KARE"

 


Tapesh_0-1627466189917.png

 

Any help or suggestion to this will be really helpful. 


Thanks a million for reading and helping. 

1 ACCEPTED SOLUTION

Accepted Solutions
v-bofeng-msft
Community Support
Community Support

Hi @Tapesh :

I'm afraid this is hard to achieve by Forall. I suggest you use a timer to create a loop to create the table and create a variable to save the new table.

I've made a test for your reference:

1\My Data source:

ClearCollect(
  ExportData,
  {ID:1,'Unit Name':{Value:Blank()}},
  {ID:2,'Unit Name':{Value:"AA"}},
  {ID:3,'Unit Name':{Value:"AA"}},
  {ID:4,'Unit Name':{Value:"AA"}},
  {ID:5,'Unit Name':{Value:"AA"}},
  {ID:6,'Unit Name':{Value:"AA"}},
  {ID:7,'Unit Name':{Value:"AA"}},
  {ID:8,'Unit Name':{Value:Blank()}},
  {ID:9,'Unit Name':{Value:"BB"}},
  {ID:10,'Unit Name':{Value:"BB"}}
)

2\Add a timer:

Duration

100 /*loop in 0.1s*/

OnSelelct

Clear(VarCollection);Set(Steps,CountRows(ExportData));Set(TheCount,0);Set(StepCount,0)

OnTimerEnd

If(
    IsBlank(
        Last(FirstN(Sort(ExportData,ID,Ascending),StepCount + 1)).'Unit Name'.Value
    ),
    Set(TheCount,0)
);
Collect(
    VarCollection,
    {
        myRecord: Last(FirstN(Sort (ExportData,ID,Ascending),StepCount + 1)),
        rowNumber: TheCount
    }
);
Set(
    TheCount,
    TheCount + 1
);
Set(
    StepCount,
    StepCount + 1
)

Repeat

StepCount<Steps

8.gif

Best Regards,

Bof

View solution in original post

2 REPLIES 2
v-bofeng-msft
Community Support
Community Support

Hi @Tapesh :

I'm afraid this is hard to achieve by Forall. I suggest you use a timer to create a loop to create the table and create a variable to save the new table.

I've made a test for your reference:

1\My Data source:

ClearCollect(
  ExportData,
  {ID:1,'Unit Name':{Value:Blank()}},
  {ID:2,'Unit Name':{Value:"AA"}},
  {ID:3,'Unit Name':{Value:"AA"}},
  {ID:4,'Unit Name':{Value:"AA"}},
  {ID:5,'Unit Name':{Value:"AA"}},
  {ID:6,'Unit Name':{Value:"AA"}},
  {ID:7,'Unit Name':{Value:"AA"}},
  {ID:8,'Unit Name':{Value:Blank()}},
  {ID:9,'Unit Name':{Value:"BB"}},
  {ID:10,'Unit Name':{Value:"BB"}}
)

2\Add a timer:

Duration

100 /*loop in 0.1s*/

OnSelelct

Clear(VarCollection);Set(Steps,CountRows(ExportData));Set(TheCount,0);Set(StepCount,0)

OnTimerEnd

If(
    IsBlank(
        Last(FirstN(Sort(ExportData,ID,Ascending),StepCount + 1)).'Unit Name'.Value
    ),
    Set(TheCount,0)
);
Collect(
    VarCollection,
    {
        myRecord: Last(FirstN(Sort (ExportData,ID,Ascending),StepCount + 1)),
        rowNumber: TheCount
    }
);
Set(
    TheCount,
    TheCount + 1
);
Set(
    StepCount,
    StepCount + 1
)

Repeat

StepCount<Steps

8.gif

Best Regards,

Bof

View solution in original post

Tapesh
Post Prodigy
Post Prodigy

Hi @v-bofeng-msft , 

Thanks a million for the solution let me give it a try and will be back soon else if works fine will make sure to accept this as a solution. 

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

secondImage

Power Apps Community Call

Please join us on Wednesday, October 20th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (2,280)