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
summer18
Helper III
Helper III

sum of value by specific week numbers

Hi, 

 

I need your help on getting the sum of specific week start and week end.  I tried running total but it's not the expected result.

My chart should look like this whether in table or bar chart:

 

sample01.png

 

It's easy to do this in Excel but could not get it correctly in PowerBI.  Please refer to the details below:

 

sample02.png

 

Here's the link of sample pbix.  

https://drive.google.com/file/d/1KRJfdfqbV88I1Y5eKE2eCvwZSMunhtdr/view?usp=sharing

 

Thanks in advance for your help and sharing your knowledge.

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@summer18 - Seems like this should be:

 

Measure =
  VAR __WeekMax = MAX('Table'[Week])
  VAR __WeekMin = __WeekMax - 6
  VAR __Table = FILTER(ALL('Table'),[Week] >= __WeekMin && [Week] <= __WeekMax)
RETURN
  IF(__WeekMin <= 0,BLANK(),SUMX(__Table,[Expenses]))

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

6 REPLIES 6
swise001
Continued Contributor
Continued Contributor

@summer18 
The PBIX file link requires a google sign-in open - please change settings in google to allow anyone with the link to download.  

 

This way - we can use your underlying table design to help you.  

Greg_Deckler
Super User
Super User

@summer18 - Seems like this should be:

 

Measure =
  VAR __WeekMax = MAX('Table'[Week])
  VAR __WeekMin = __WeekMax - 6
  VAR __Table = FILTER(ALL('Table'),[Week] >= __WeekMin && [Week] <= __WeekMax)
RETURN
  IF(__WeekMin <= 0,BLANK(),SUMX(__Table,[Expenses]))

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler ,

Thanks for your help. Your formula worked on my issue.  I just added Year in the formula so that the calculation will still be in the same year

 

Measure =
  VAR __WeekMax = MAX('Table'[Week])
  VAR __WeekMin = __WeekMax - 6
  VAR __Table = FILTER(ALL('Table'),

                                  'Table'[Year] = MAX( 'Table'[Year]) &&

[Week] >= __WeekMin && [Week] <= __WeekMax)
RETURN
  IF(__WeekMin <= 0,BLANK(),SUMX(__Table,[Expenses]))
 

@summer18 - Awesome! Glad to hear it. Yes, good call on the year!


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @amitchandak I tried the Week Start Date and Week End Date before posting my topic but I could not get it to work correctly on my scenario. Since you provided me on my previous post your blog links, I always refer to them and they're really helpful. Thanks for that

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.