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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
LukeReds
Helper II
Helper II

Sum n values in a table with List.Range

Hi to everyone,

i have a table like in the pic, i want to sum 4 value per rows, for example

row1:  135

rowe2: 135+165

row3: 135+165+195

row4: 135+165+195+225

row5:: 165+195+225+325

row6:  195+225+325+180

and  so on

 

I use this formula but it give me a wrong number of elements, someone could explain me why? And what have i to correct? In "list" (pic below) i aspected to have 4 elements...

 

if [week]< 4 then List.Range (Source[value], 0,[week]) else List.Range (Source[value], [week]-3,[week]-1)

 

Thank you in advance

 

tab.jpg

 

2 ACCEPTED SOLUTIONS
Fowmy
Super User
Super User

@LukeReds 

Try this way: 

List.Range(Source[value],  [week]- 4, 4) 


Create a blank Query, go to the Advanced Editor, clear the existing code, and paste the codes give below and follow the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Lc25DQAxCETRXogdcPmqBbn/NpZZyB5fSBNBQoPEJr0RpPAqG3zLnlYtz7S1F34O/97oUv2gc/WLvqsL5+HcB5a9lwXTjun3AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [week = _t, value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"week", Int64.Type}, {"value", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.Range(Source[value],  [week]- 4, 4) )
in
    #"Added Custom"

  

Fowmy_0-1704534221708.png


List.Range works with an offset and a count:

List.Range(list as list, offset as number, optional count as nullable number) as list



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

LukeReds
Helper II
Helper II

thank you Fowmy, shkran lak

View solution in original post

2 REPLIES 2
LukeReds
Helper II
Helper II

thank you Fowmy, shkran lak

Fowmy
Super User
Super User

@LukeReds 

Try this way: 

List.Range(Source[value],  [week]- 4, 4) 


Create a blank Query, go to the Advanced Editor, clear the existing code, and paste the codes give below and follow the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Lc25DQAxCETRXogdcPmqBbn/NpZZyB5fSBNBQoPEJr0RpPAqG3zLnlYtz7S1F34O/97oUv2gc/WLvqsL5+HcB5a9lwXTjun3AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [week = _t, value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"week", Int64.Type}, {"value", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.Range(Source[value],  [week]- 4, 4) )
in
    #"Added Custom"

  

Fowmy_0-1704534221708.png


List.Range works with an offset and a count:

List.Range(list as list, offset as number, optional count as nullable number) as list



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors
Top Kudoed Authors