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
sauliux
Frequent Visitor

Grouping Times Series Data

In short I have manually recorded luxmeter data with values of interest, and 0 values inbetween (in order to keep track of which measurements are for which sample).
I want to group this time series data highs in a serial fashion, and I am struggling to figure out how to write the conditional statements for the "Custom Column" (I suspect the magical "List.Generate" and "Custom Function" have something to do with it).
So far I was able to "find" the data boundaries of interest ("FALSE" values in the "Data Boundries" column from the image below), but serial numbering the time series data highs is turning out to be a challenge:

sauliux_1-1666785828468.png

I was hoping that declaring a variable (in this case "n"), and then in an if conditional statement adding one to it (n=n+1) would allow me to number my groups. Apparently the variable is immutable?
For the current stage I am hoping to achieve the following:

sauliux_2-1666786923624.png

At a later stage I would filter out the 0 values from the "Custom" column, group the data by "Data Boundries" column, average the the 5 "middle" values  in the grouped "Data Boundries" tables (last and first 2-3 measurements of each group contain discrepancies)
Suggestions how incorporate n=n+1 into the custom column function would be highly appreciated. 

1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

Hi @sauliux ,
you can do this with special grouping parameters: (If you are interested: Table.Group: Exploring the 5th element in Power BI and Power Query – The BIccountant )

 

let
  Source = = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], 
  #"Changed Type" = Table.TransformColumnTypes(
    Source, 
    {
      {"Record Time", type text}, 
      {"Solar", Int64.Type}, 
      {"Index", Int64.Type}, 
      {"Custom", Int64.Type}, 
      {"Custom1", Int64.Type}, 
      {"Data_Boundries", type any}
    }
  ), 
  #"Grouped Rows" = Table.Group(
    #"Changed Type", 
    {"Data_Boundries"}, 
    {{"Count", each _}}, 
    GroupKind.Local, 
    (group, current) => Number.From(current[Data_Boundries] = false)
  ), 
  #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1, Int64.Type), 
  #"Expanded Count" = Table.ExpandTableColumn(
    #"Added Index", 
    "Count", 
    {"Record Time", "Solar", "Index", "Custom", "Custom1", "Data_Boundries"}, 
    {"Record Time", "Solar", "Index.1", "Custom", "Custom1", "Data_Boundries.1"}
  ), 
  #"Added Custom" = Table.AddColumn(
    #"Expanded Count", 
    "Custom.1", 
    each if [Data_Boundries.1] = 0 then 0 else [Index]
  ), 
  #"Removed Columns" = Table.RemoveColumns(
    #"Added Custom", 
    {"Data_Boundries", "Data_Boundries.1", "Index"}
  ), 
  #"Renamed Columns" = Table.RenameColumns(#"Removed Columns", {{"Custom.1", "Data_Boundries"}})
in
  #"Renamed Columns"

 


See also attached file.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

7 REPLIES 7
ImkeF
Community Champion
Community Champion

Hi @sauliux ,
you can do this with special grouping parameters: (If you are interested: Table.Group: Exploring the 5th element in Power BI and Power Query – The BIccountant )

 

let
  Source = = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], 
  #"Changed Type" = Table.TransformColumnTypes(
    Source, 
    {
      {"Record Time", type text}, 
      {"Solar", Int64.Type}, 
      {"Index", Int64.Type}, 
      {"Custom", Int64.Type}, 
      {"Custom1", Int64.Type}, 
      {"Data_Boundries", type any}
    }
  ), 
  #"Grouped Rows" = Table.Group(
    #"Changed Type", 
    {"Data_Boundries"}, 
    {{"Count", each _}}, 
    GroupKind.Local, 
    (group, current) => Number.From(current[Data_Boundries] = false)
  ), 
  #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1, Int64.Type), 
  #"Expanded Count" = Table.ExpandTableColumn(
    #"Added Index", 
    "Count", 
    {"Record Time", "Solar", "Index", "Custom", "Custom1", "Data_Boundries"}, 
    {"Record Time", "Solar", "Index.1", "Custom", "Custom1", "Data_Boundries.1"}
  ), 
  #"Added Custom" = Table.AddColumn(
    #"Expanded Count", 
    "Custom.1", 
    each if [Data_Boundries.1] = 0 then 0 else [Index]
  ), 
  #"Removed Columns" = Table.RemoveColumns(
    #"Added Custom", 
    {"Data_Boundries", "Data_Boundries.1", "Index"}
  ), 
  #"Renamed Columns" = Table.RenameColumns(#"Removed Columns", {{"Custom.1", "Data_Boundries"}})
in
  #"Renamed Columns"

 


See also attached file.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

sauliux
Frequent Visitor

@ImkeF That was so smooth. Thank you very much.
I suspect that a lot of the M code List.Accumulate() and/or List.Generate() loop examples that I have come across could have been done using your Table.Group() technique.

ImkeF
Community Champion
Community Champion

Hi @sauliux ,
having trouble understanding your request.
Could you please proved sample data with a "before" and "after" example in a usable format like described here?:

https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

sauliux
Frequent Visitor

Sorry, but I have tried everything, including spreadsheet to HTML table generators, and cannot reproduce what you have requested in "in a usable format like described here".
Look, even if I generate the HTML table with with forum toolbar and fill it manualy it still throws HTML errors...

I have created a ""before" sample data" .csv file, uploaded it to Onedrive, and it's available via the following URL: https://1drv.ms/u/s!Avj2FfL1S_6RnBSVJ886R9rVtp9N?e=NLGnCd

"before" sample data

Record TimeSolarIndexCustomCustom1Data_Boundries
18-10-2022 14:01:012791111
18-10-2022 14:01:02402,82101
18-10-2022 14:01:0303000
18-10-2022 14:01:0404000
18-10-2022 14:01:0505000
18-10-2022 14:01:0606000
18-10-2022 14:01:0707000
18-10-2022 14:01:0808000
18-10-2022 14:01:0909000
18-10-2022 14:01:10010000
18-10-2022 14:01:1101101FALSE
18-10-2022 14:01:12513,712111
18-10-2022 14:01:13473,713111
18-10-2022 14:01:14473,314111
18-10-2022 14:01:15482,215111
18-10-2022 14:01:16480,516111
18-10-2022 14:01:17480,517111
18-10-2022 14:01:18481,618111
18-10-2022 14:01:19480,519111
18-10-2022 14:01:20478,820111
18-10-2022 14:01:21485,721101
18-10-2022 14:01:22022000
18-10-2022 14:01:23023000
18-10-2022 14:01:24024000
18-10-2022 14:01:25025000
18-10-2022 14:01:26026000
18-10-2022 14:01:27027000
18-10-2022 14:01:28028000
18-10-2022 14:01:29029000
18-10-2022 14:01:30030000
18-10-2022 14:01:3103101FALSE
18-10-2022 14:01:32291,832111
18-10-2022 14:01:3332133111
18-10-2022 14:01:34321,634111
18-10-2022 14:01:35321,635111
18-10-2022 14:01:36321,336111
18-10-2022 14:01:37321,337111
18-10-2022 14:01:38321,338111
18-10-2022 14:01:3932139111
18-10-2022 14:01:40321,340111
18-10-2022 14:01:41321,341111
18-10-2022 14:01:42321,642101
18-10-2022 14:01:43043000
18-10-2022 14:01:44044000
18-10-2022 14:01:45045000
18-10-2022 14:01:46046000
18-10-2022 14:01:47047000

"after" sample data

Record TimeSolarIndexCustomCustom.1Data Boundries
18-10-2022 14:01:012791111
18-10-2022 14:01:02402,82101
18-10-2022 14:01:0303000
18-10-2022 14:01:0404000
18-10-2022 14:01:0505000
18-10-2022 14:01:0606000
18-10-2022 14:01:0707000
18-10-2022 14:01:0808000
18-10-2022 14:01:0909000
18-10-2022 14:01:10010000
18-10-2022 14:01:11011012
18-10-2022 14:01:12513,712112
18-10-2022 14:01:13473,713112
18-10-2022 14:01:14473,314112
18-10-2022 14:01:15482,215112
18-10-2022 14:01:16480,516112
18-10-2022 14:01:17480,517112
18-10-2022 14:01:18481,618112
18-10-2022 14:01:19480,519112
18-10-2022 14:01:20478,820112
18-10-2022 14:01:21485,721102
18-10-2022 14:01:22022000
18-10-2022 14:01:23023000
18-10-2022 14:01:24024000
18-10-2022 14:01:25025000
18-10-2022 14:01:26026000
18-10-2022 14:01:27027000
18-10-2022 14:01:28028000
18-10-2022 14:01:29029000
18-10-2022 14:01:30030000
18-10-2022 14:01:31031013
18-10-2022 14:01:32291,832113
18-10-2022 14:01:3332133113
18-10-2022 14:01:34321,634113
18-10-2022 14:01:35321,635113
18-10-2022 14:01:36321,336113
18-10-2022 14:01:37321,337113
18-10-2022 14:01:38321,338113
18-10-2022 14:01:3932139113
18-10-2022 14:01:40321,340113
18-10-2022 14:01:41321,341113
18-10-2022 14:01:42321,642103
18-10-2022 14:01:43043000
18-10-2022 14:01:44044000
18-10-2022 14:01:45045000
18-10-2022 14:01:46046000
18-10-2022 14:01:47047000

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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.