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
gopichilla
Resolver III
Resolver III

previous week sales.

Hi All,

 

I want previous week sales anyone can send me DAX query.

 

Thanks

1 ACCEPTED SOLUTION
Eric_Zhang
Employee
Employee


@gopichilla wrote:

Hi All,

 

I want previous week sales anyone can send me DAX query.

 

Thanks


@gopichilla

You'll need a calendar table as below.

calendar =
VAR TEMPTBL =
    ADDCOLUMNS (
        CALENDAR ( "2016-12-31", "2017-12-31" ),
        "Year", YEAR ( [Date] ),
        "weekNo", WEEKNUM ( [Date] ),
        "YearWeek", CONCATENATE (
            YEAR ( [Date] ),
            RIGHT ( CONCATENATE ( "0", WEEKNUM ( [Date] ) ), 2 )
        )
    )
RETURN
    ADDCOLUMNS ( TEMPTBL, "WeekIndex", RANKX ( TEMPTBL, [YearWeek],, ASC, DENSE ) )

Then create a one to many relationship from calendar table to data table. Then use a measure as below to get the previous week's value.

previous week value =
CALCULATE (
    SUM ( data[value] ),
    FILTER (
        ALLSELECTED ( 'calendar' ),
        MAX ( 'calendar'[WeekIndex] )
            = 'calendar'[WeekIndex] + 1
    )
)

Capture.PNG

 

 

See more details in the attached pbix file.

View solution in original post

6 REPLIES 6
Eric_Zhang
Employee
Employee


@gopichilla wrote:

Hi All,

 

I want previous week sales anyone can send me DAX query.

 

Thanks


@gopichilla

You'll need a calendar table as below.

calendar =
VAR TEMPTBL =
    ADDCOLUMNS (
        CALENDAR ( "2016-12-31", "2017-12-31" ),
        "Year", YEAR ( [Date] ),
        "weekNo", WEEKNUM ( [Date] ),
        "YearWeek", CONCATENATE (
            YEAR ( [Date] ),
            RIGHT ( CONCATENATE ( "0", WEEKNUM ( [Date] ) ), 2 )
        )
    )
RETURN
    ADDCOLUMNS ( TEMPTBL, "WeekIndex", RANKX ( TEMPTBL, [YearWeek],, ASC, DENSE ) )

Then create a one to many relationship from calendar table to data table. Then use a measure as below to get the previous week's value.

previous week value =
CALCULATE (
    SUM ( data[value] ),
    FILTER (
        ALLSELECTED ( 'calendar' ),
        MAX ( 'calendar'[WeekIndex] )
            = 'calendar'[WeekIndex] + 1
    )
)

Capture.PNG

 

 

See more details in the attached pbix file.

I wonder why its not working for me

Hi @ApurvaKhatri,

 

Share more details.  Share your dataset and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Values.JPGVal1.JPGC

 

Hello @Ashish_Mathur

Curent Sum is a measure.

I need the difference of Oct 25 and Oct 18 to be displayed in another column.Similarly Oct 18 - oct 11 i.e 87 - 80 so 4 should be displayed. Like wise for all the value differences

Hi,

 

Share the link from where i can download your file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks it is working fine.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.