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
Anonymous
Not applicable

Calculate/Display % sales difference this weeks sales on this week last year.

Hi All

I have a table showing volume sales by date. What i want to do is to provide a table and graph showing the % difference of the [Pallets] for this week vs this week last year. I figured i need a measure that is the % difference of the [Pallets] for this date vs this date last year. The key fields are;

Pallet sales = [Pallets] - Integer

Order date = [Order Date] - Date

 

I tried the below measure to calculate % difference date on date, but this is not working right.

 

divide(calculate(sum(qryHistoryStats[Pallets]),SAMEPERIODLASTYEAR(qryHistoryStats[Order Date].[Date])) - sum([Pallets]),calculate(sum(qryHistoryStats[Pallets]),SAMEPERIODLASTYEAR(qryHistoryStats[Order Date].[Date])))

Is my approach correct (in which case what is wrong with my measure) or is there another way to achieve this?

 

4 REPLIES 4
v-lili6-msft
Community Support
Community Support

hi, @Anonymous

You may try to add a weeknum column and drag it into visual

Weeknum = WEEKNUM(qryHistoryStats[Order Date]) 

Then use your formula

difference% = 
DIVIDE (
    SUM ( [Pallets] ) // this weeks sales
    - CALCULATE (
        SUM ( qryHistoryStats[Pallets] ),
        SAMEPERIODLASTYEAR ( qryHistoryStats[Order Date].[Date] )
    ) // difference between this weeks sales on this week last year
        ,
    CALCULATE (
        SUM ( qryHistoryStats[Pallets] ),
        SAMEPERIODLASTYEAR ( qryHistoryStats[Order Date].[Date] )
    ) // on this week last year
)

Result:

10.JPG

Best Regards,

Lin

 

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Lin, thanks.

 

Week number is already a field in the data. Below is a sample of the data.

 

PcntDiff data.PNG

 

I used your formula but the measure returns zero on every row - PcntDiff on below snapshot table

 

PcntDiff.PNG

 

I broke the formula down to see the the results of the 2 parts;

  • SUM ( qryHistoryStats[Pallets] ) works OK - This Week on the above
  • SAMEPERIODLASTYEAR ( qryHistoryStats[Order Date].[Date] ) returns the same value as the current year - Last Year Wk on the above

So the full formula essentially calculates as (x-x) / x

Why would SAMEPERIODLASTYEAR not return the correct Data?

 

 

hi, @Anonymous 

Sorry for the late reply, SAMEPERIODLASTYEAR ( qryHistoryStats[Order Date].[Date] ) is used date hierarchy of qryHistoryStats[Order Date].

And from your screenshot, It seems that you just use year field, 

You should use [Order Date] field in the visual like this:

17.JPG18.JPG

 

If it is not your case, please share pbix file or some data sample and expected output. Do mask sensitive data before uploading.

 

 

 

Best Regards,

Lin

 

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_Deckler
Super User
Super User

Time Intelligence functions can be tricky. See if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.