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
bo_afk
Post Patron
Post Patron

Current week vs last week sum

Hi,

 

I have a dataset containing week numbers and sales figures associated to each week, along with other columns such as market, product etc.

 

How would do I create a measure to compare the sales figures between one week and the previous week? Assuming that I have a table displaying current weeks' sales.

 

Thanks

 

afk

1 ACCEPTED SOLUTION

Hi @bo_afk ,

You can add allselected function to get current last week number and use it to find out correspond amount:

CW Sales =
VAR CW =
    CALCULATE ( MAX ( Table[WeekNum] ), ALLSELECTED ( Table ) )
RETURN
    CALCULATE (
        SUM ( Table[Sales] ),
        FILTER ( ALLSELECTED ( Table ), Table[WeekNum] = CW )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

4 REPLIES 4
arpitsa
Frequent Visitor

i want to calculate last week vs current week comparison bases on total backoffice cases [ for eg previous week it is 100 and this week till date 110 so variance is +10 ] and i need to show this value in power Bi Card visual

 

Can someone please assist me in - i have tried referrring various sites but i am not getting appropriate codes

v-shex-msft
Community Support
Community Support

Hi @bo_afk ,

You can use following measure formula if it suitable for your requirement:

Diff =
VAR currWeek =
    MAX ( Table[WeekNum] )
RETURN
    CALCULATE (
        SUM ( Table[Sales] ),
        FILTER ( ALLSELECTED ( Table ), [WeekNum] = currWeek ),
        VALUES ( Table[Product] ),
        VALUES ( Table[Market] )
    )
        - CALCULATE (
            SUM ( Table[Sales] ),
            FILTER ( ALLSELECTED ( Table ), [WeekNum] = currWeek - 1 ),
            VALUES ( Table[Product] ),
            VALUES ( Table[Market] )
        )

If above not help, please share some sample data for test.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Thanks for your response @v-shex-msft.

 

I've however encountered an issue in cases where a particular product does not have any sales for the current week. I currently have a measure that just to looks at the CW sales figures as per below.

 

CW Sales = 
var CW = max(Table[WeekNum])
RETURN 
CALCULATE (sum (Table[Sales]), Table[WeekNum] = CW)

But it's returning results even for products that aren't sold in the CW. Looks like it is taking the max week for THAT product and then returning the sales associated to that week as opposed to the latest week overall in the data.

 

How can I fix this?

 

Hi @bo_afk ,

You can add allselected function to get current last week number and use it to find out correspond amount:

CW Sales =
VAR CW =
    CALCULATE ( MAX ( Table[WeekNum] ), ALLSELECTED ( Table ) )
RETURN
    CALCULATE (
        SUM ( Table[Sales] ),
        FILTER ( ALLSELECTED ( Table ), Table[WeekNum] = CW )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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.