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

YTD Average of a Cumulative Measure

I'm struggling and need some help. Per another post, I created a measure that counts the number of unique customers that exist in a 13 week period prior to DimWeek[Week_Num]. This is a cumulative measure because it calculates total distinct values in the time period. Now, I want to create a measure that calculates the YTD average of this L13W measure. We'll call this new measure "ACT_POCS_YTDAVG"

 

Code for the existing L13W Measure.

 

ACT_POCS_L13Wchart = 
   Calculate(
       DISTINCTCOUNT(Sales_Data[Customer]), 
          FILTER(ALLSELECTED(Sales_Data),
              Sales_Data[Week_Num]<=Sales_Data[Week_Num]) &&
              Sales_Data[Week_Num]>=MAX(DimWeek[Week_Num])-13)
            )
       

 

 

Table showing desired value of ACT_POCS_YTDAVG

6-12-2018 11-22-03 AM.png

 

 

The DISTINCTCOUNT makes this difficult for me. Is there any way to make a measure to do this, or do I need to convertACT_POCS_L13W to a calculated column instead?

3 REPLIES 3
v-juanli-msft
Community Support
Community Support

Hi @modelmike

I test with your example shown on the picture

Create measures

Measure2 = MAX([Week_num])
Measure3 = CALCULATE(SUMX(FILTER(ALL(Sheet1),[Week_num]<=MAX([Week_num])),[Measure1]))/[Measure2]

11.png

 

Best regards

Maggie

Hi @

 

 

 

MAXWeek = MAX(Sales_Data[Week_Num])
ACT_POCS_YTDAVG = 
     CALCULATE(
        SUMX(
            FILTER(ALL(Sales_Data),
                SalesData[Week_Num]<MAX(DimWeek[Week_Num]))
            ,_distribution[ACT_PODS_L13WChart]) --Original Measure aka Measure 1
    )
    / _distribution[MAXWeek] --aka Measure 2
       

 

 

 

 

Hi @modelmike

Yes, you are right, the SUMX function might affect the execution performance, especially nested SUMX.

You could refer to below blogs to optimizie DAX formula.

Tune your powerpivot dax query don’t use the entire table in a filter and replace sumx if possible

Nested sumx or dax query

 

 

Best Regards

Maggie

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.