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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Rahul_SC
Helper III
Helper III

How to define dynamically sum of last five columns

Hi All,

 

I need to create a table in power bi where need to show data of last five weeks on weekly basis. Just like, I did in the picture below. This I have prepared these columns in power query then loaded to desktop. Now, everyweek I need to revmove the most previous week (i.e-week 18) then add new week (i.e-week 23) and need to show sum in canceled sailing column from week 19-23 same in scheduled sailing col. For this, everyweek when next week data is updated in the source file then I have to open power query then do calculation as per the recent week (19-23) then in power bi desktop also remove col of week 18 and add new week col (week 23) to show the current data. This takes a lot of time each week.

 

Rahul_SC_0-1654568183000.png

I want to make it dynamic, means I just need to refresh then new week data is added in the table. I do not need to open power query each time. 

 

I thought of a solution like creating a saparate data col for week and data for cancel sailing would use it. 

 

I need to know a function which is used for adding based on last five columns. or any other way of getting this done.

 

Regards,

 

2 ACCEPTED SOLUTIONS
KT_Bsmart2gethe
Impactful Individual
Impactful Individual

Hi @Rahul_SC ,

 

What you can do in this case is to add the remove column step.

 

To turn the step into dynamically pick up the last six weeks:

Add a custom step:

Table.RemoveColumns(Previous step, List.RemoveLastN(List.Sort(List.Select(Table.ColumnNames(Previous step), each Text.Contains(_,"Week ")), Order.Ascending),6))

 

Let me know if this helps you to resolve your challenge.

 

Regards

KT

View solution in original post

Vijay_A_Verma
Super User
Super User

For dynamically adding last 5 columns, use below formula (you can keep adding columns and formula is not required to be changed)

= List.Sum(List.LastN(Record.ToList(_),5))

View solution in original post

3 REPLIES 3
Vijay_A_Verma
Super User
Super User

For dynamically adding last 5 columns, use below formula (you can keep adding columns and formula is not required to be changed)

= List.Sum(List.LastN(Record.ToList(_),5))
KT_Bsmart2gethe
Impactful Individual
Impactful Individual

Hi @Rahul_SC ,

 

What you can do in this case is to add the remove column step.

 

To turn the step into dynamically pick up the last six weeks:

Add a custom step:

Table.RemoveColumns(Previous step, List.RemoveLastN(List.Sort(List.Select(Table.ColumnNames(Previous step), each Text.Contains(_,"Week ")), Order.Ascending),6))

 

Let me know if this helps you to resolve your challenge.

 

Regards

KT

@Vijay_A_Verma , thanks for responding.

 

@KT_Bsmart2gethe a big thanks to Kirwin. You helped me a lot from the beginning till my end outcome what I excatly wanted. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors