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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
2025cindy
Frequent Visitor

Loop

2025cindy_0-1667955368259.png

I would like to use loop to obtain a table as follows,

00 4
01 9
02 9
03 9
04 8

At 00 Clock, total count is 4 as Discharge Date as no patient Discharge Date is equal to 00. 4 - 0 = 4

At 01 Clock, total count is 9 as there is 0 patient EDIS Discharge Date is <= to 01,
9 - 0 = 9

At 02 Clock, total count is 9 as there is 1 patient who's EDIS Discharge Date is <= 02.
10 - 1 = 9

At 03 Clock, total count is 9 as there is 2 patients who's EDIS Discharge Date is <= 03.
11 - 2 = 9

At 04 Clock, total count is 9 as there is 5 patients who's EDIS Discharge Date is <=04.
13 - 5 = 8

discharge date update frequently, some discharge date is null before update.

1 ACCEPTED SOLUTION
wdx223_Daniel
Community Champion
Community Champion

NewStep = #table(
                     {"Clock","Count"},
                     Record.ToList(
                                   List.Accumulate(
                                                   Table.ToRecords(PreviousStepName),
                                                   {[],List.Repeat({0},25),1},
                                                   (x,y)=>let
                                                             a=Time.Hour(y[EDIS Discharge Date])??24,
                                                             b=List.ReplaceRange(x{1},a,1,{x{1}{a}+1}),
                                                             c=Record.TransformFields(x{0},{y[Clock],each {y[Clock],x{2}-List.Sum(List.FirstN(b,Number.From(y[Clock])+1))}},2)
                                                          in
                                                            {c,b,x{2}+1}
                                                  ){0}
                                  )
                    )

View solution in original post

1 REPLY 1
wdx223_Daniel
Community Champion
Community Champion

NewStep = #table(
                     {"Clock","Count"},
                     Record.ToList(
                                   List.Accumulate(
                                                   Table.ToRecords(PreviousStepName),
                                                   {[],List.Repeat({0},25),1},
                                                   (x,y)=>let
                                                             a=Time.Hour(y[EDIS Discharge Date])??24,
                                                             b=List.ReplaceRange(x{1},a,1,{x{1}{a}+1}),
                                                             c=Record.TransformFields(x{0},{y[Clock],each {y[Clock],x{2}-List.Sum(List.FirstN(b,Number.From(y[Clock])+1))}},2)
                                                          in
                                                            {c,b,x{2}+1}
                                                  ){0}
                                  )
                    )

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.