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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
RYOH_0130
New Member

Issue with Calculating Cumulative Sales for Same Weekday Last Year

Hello Power BI Community,

I am encountering an issue with calculating the cumulative sales for the same weekday last year. Here are the key details of the problem:

  1. Same Weekday Last Year:

    • I am not looking to calculate cumulative sales for the same date last year but for the same weekday last year.
      (ex. this year:2024.May.1st(Sat) -> Same Weekday Last Year : 2023.May.3rd(Sat))
  2. Data Structure:

    • The column for the same weekday last year is not in the calendar table but is in a separate table. I have established a relationship between this table and the calendar table.
      RYOH_0130_1-1721619975608.png

       

  3. Objective:

    • I want to calculate the cumulative sales of "RegisterPrice" from the Purchase_Data table for the same weekday last year using a DAX measure.
  4. Current Issue:

    • The current measure I have returns all blank values instead of the cumulative sales for the same weekday last year.

Current Measure:

Here is the current DAX measure that I am using:

Cumulative Sales for Same Weekday Last Year (in Millions) = 
VAR MaxCurrentDate = MAX('Calendar_Table'[Date])
VAR PreviousDate = CALCULATE(
    MAX('Previous_Date_Table'[SameWeekdayLastYearDate]),
    'Previous_Date_Table'[SameWeekdayLastYearDate] <= MaxCurrentDate
)
RETURN
CALCULATE(
    SUMX(
        FILTER(
            ALL('Previous_Date_Table'),
            'Previous_Date_Table'[SameWeekdayLastYearDate] <= PreviousDate
        ),
        CALCULATE(
            SUM('Purchase_Data'[RegisterPrice]),
            TREATAS(
                VALUES('Previous_Date_Table'[SameWeekdayLastYearDate]),
                'Calendar_Table'[Date]
            )
        )
    )
) / 1000000

Explanation:

  1. MaxCurrentDate:

    • Retrieves the maximum current date from the calendar table.
  2. PreviousDate:

    • Retrieves the corresponding same weekday last year date up to the current date.
  3. SUMX and FILTER:

    • Calculates cumulative sales for the same weekday last year.

Despite this, the measure returns blank values.

Could you please help me identify what I might be doing wrong and how to correct this measure?

Thank you in advance for your assistance.

1 ACCEPTED SOLUTION

Hi @RYOH_0130 ,

 

I did simple samples, mainly for the same weekday screenings last year for the study and you can check the results below:

vtianyichmsft_0-1722244237358.png

 

LastYearSameWeekDay = var _t = ADDCOLUMNS('Table',"a",SUMX(FILTER(ALL('Table'),YEAR([Date])=YEAR(EARLIER([Date]))-1&&MONTH([Date])=MONTH(EARLIER([Date]))&&DAY([Date])>=DAY(EARLIER([Date]))-7&&WEEKDAY([Date])=WEEKDAY(EARLIER([Date]))),[Value]))
RETURN SUMX(_t,[a])

 

 

An attachment for your reference. Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-tianyich-msft
Community Support
Community Support

Hi @RYOH_0130 ,

 

Not sure about your date table, please provide sample data that maps your data model

 

Best regards,
Community Support Team_ Scott Chang

Dear @v-tianyich-msft 

Thank you for your response.
Please find below the sample data for the data map for your review.

Best regads,
Ryo

Previous Data Table
DateDaySameWeekday
Last Year's Date
Last Year's Day
3-Jan-20Fri4-Jan-19Fri
10-Jan-20Fri11-Jan-19Fri
17-Jan-20Fri18-Jan-19Fri
24-Jan-20Fri25-Jan-19Fri
31-Jan-20Fri1-Feb-19Fri
1-Jan-21Fri3-Jan-20Fri
8-Jan-21Fri10-Jan-20Fri
    
Calender Table
Date,Year_yyyy,Month_Value,Day_Value,
1-May-17201751
2-May-17201752
3-May-17201753
4-May-17201754
5-May-17201755
6-May-17201756
7-May-17201757
    
GGCA_Purchase_data 
ReceptionDateRegisterPriceRegisterPriceTaxIn 
1-May-1710001100 
2-May-1715001650 
3-May-1720002200 
4-May-1710001100 
5-May-1712001320 

Hi @RYOH_0130 ,

 

I did simple samples, mainly for the same weekday screenings last year for the study and you can check the results below:

vtianyichmsft_0-1722244237358.png

 

LastYearSameWeekDay = var _t = ADDCOLUMNS('Table',"a",SUMX(FILTER(ALL('Table'),YEAR([Date])=YEAR(EARLIER([Date]))-1&&MONTH([Date])=MONTH(EARLIER([Date]))&&DAY([Date])>=DAY(EARLIER([Date]))-7&&WEEKDAY([Date])=WEEKDAY(EARLIER([Date]))),[Value]))
RETURN SUMX(_t,[a])

 

 

An attachment for your reference. Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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