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
Likhitha
Helper IV
Helper IV

Doubt in calculating sum of last 6 weeks sum

Hello All,

I'm having 52 weeks data in 2019 and 3 weeks data in 2020.I want to calculate last 6 weeks sales sum.

if i select 1st week in 2020 i need need to do sum from 1-2020 to 47-2019.

How to achieve that? 

2 ACCEPTED SOLUTIONS

Hi @Likhitha ,

If you are using a date table, this is doable. If not, then it is a lot harder. I am going to assume you do have a datetable. We are going to need a yearweek column in the format yyyyww (eg 202001 for week 1 in 2020). Then we are going to add a column in your date table that ranks all yearweek in a densly matter. Like this:

image.png 

The formula of the datetable and the added column are these:

DateTable = ADDCOLUMNS(CALENDAR("01/01/2017", "31/12/2020"), 
     "yearweek", 
     CONCATENATE(FORMAT(YEAR([Date]), "####"), FORMAT(WEEKNUM([Date]), "0#")))
RankedYearWeek = RANKX(DateTable, DateTable[yearweek], , ASC, Dense)

Now you need to link your date table to the date column in your fact table. Depending on your datamodel and columns, you can calculate what dates are in the past 6 weeks by looking at the current RankedYearWeek and subtract 6. This is quite an advanced solution that might require you to rethink your datamodel but I would suit your needs.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

Hi @Likhitha ,

 

check this out.

PBIX

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


View solution in original post

13 REPLIES 13

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.