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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Prior week sales for week 1.

Hi,

 

Can someone help me with the Dax code;

I trying to write Dax for Prior Week Sales; I have the code and it is working for all weeks except for First week of the year; How do I get the Prior week sales for first week. The tricky part for me is , the prior week can be 53 rd or 52 nd week depending on the number of weeks last year had. Any help is appreciated. Thanks!!

PRIOR WTD = 
    IF(HASONEVALUE('Dim Date' [Year Number])
       && HASONEVALUE('Dim Date' [Week Number]),
            CALCULATE( Sum('Fact Daily Sales'[Sales]),
                    FILTER( ALL('Dim Date'),
                    'Dim Date'[Year Number]=VALUES('Dim Date'[Year Number])
                     && 'Dim Date'[Week Number]= Values('Dim Date'[Week Number])-1
                     && 'Dim Date'[Calendar Date]<=Max('Dim Date'[Calendar Date])
                          )
     ) ,
     BLANK()
    )   
1 ACCEPTED SOLUTION
LivioLanzo
Solution Sage
Solution Sage

Hi @Anonymous,

 

you need to add to your calendar table a column where week numbers do not reset at the start of each year, i think it should be in this post I answered:

 

https://community.powerbi.com/t5/Desktop/Get-weekly-change-first-hour-in-week-compared-to-previous-weeks/m-p/600111#M285462

 


 


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


Proud to be a Datanaut!  

View solution in original post

2 REPLIES 2
v-yuta-msft
Community Support
Community Support

@Anonymous,

 


I trying to write Dax for Prior Week Sales; I have the code and it is working for all weeks except for First week of the year; How do I get the Prior week sales for first week. The tricky part for me is , the prior week can be 53 rd or 52 nd week depending on the number of weeks last year had. Any help is appreciated. Thanks!!

PRIOR WTD = 
    IF(HASONEVALUE('Dim Date' [Year Number])
       && HASONEVALUE('Dim Date' [Week Number]),
            CALCULATE( Sum('Fact Daily Sales'[Sales]),
                    FILTER( ALL('Dim Date'),
                    'Dim Date'[Year Number]=VALUES('Dim Date'[Year Number])
                     && 'Dim Date'[Week Number]= Values('Dim Date'[Week Number])-1
                     && 'Dim Date'[Calendar Date]<=Max('Dim Date'[Calendar Date])
                          )
     ) ,
     BLANK()
    )   

 

Could you share some sample data and clarify more details about your requirement?

 

Community Support Team _ Jimmy Tao

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

LivioLanzo
Solution Sage
Solution Sage

Hi @Anonymous,

 

you need to add to your calendar table a column where week numbers do not reset at the start of each year, i think it should be in this post I answered:

 

https://community.powerbi.com/t5/Desktop/Get-weekly-change-first-hour-in-week-compared-to-previous-weeks/m-p/600111#M285462

 


 


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


Proud to be a Datanaut!  

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.