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

How to get sum of sales from Max weeks in a quarter

Hi,


I have a table with quarters and weeks, where the sales is a snapshot of the sales at x weeks into the quarter (cumulative). I'd like to get a sum of all sales filtering only for the latest weeks in the quarter (lines in red below).

 

The issue I'm running into is that the Max-Weeks formula I use tends to only capture the absolute max of all weeks and ignores the max weeks per quarter. The formula I'm working with is below. Any help?

 

QtrWeeksSales
Q111000
Q121200
Q131500
Q141600
Q21500
Q22600
Q23800
Q241000
Q31200
Q32400
Q33600
Q34800
Q41200
Q42300

 

Measure =
var MaxWk = MAX(Table[Weeks])

return
CALCULATE(
    SUM(Table[Sales]),
    Weeks = MaxWk)
1 REPLY 1
Greg_Deckler
Super User
Super User

@AudiencesQuesti Try something like:

Measure = 
  VAR __Table = SUMMARIZE( 'Table', [Qtr], "__MaxWeek", MAX( 'Table'[Week] ) )
  VAR __Table1 = 
    ADDCOLUMNS( 
      __Table, 
      "__Sales", 
          VAR __Qtr = [Qtr]
          VAR __Result = SUMX(FILTER('Table', [Qtr] = __Qtr && [Week] = [__MaxWeek]), [Sales])
      RETURN
        __Result
    )
  VAR __Result = SUMX( __Table1, [__Sales] )
RETURN
  __Result


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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