cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper V
Helper V

Subtotals for a previous week

Hello,

I have two tables: Calendar table (with Data, Year, Qtr, Month and Week fields) and SalesTable (with de Sales field). I need the difference between sales of week previous year (column DIF)

 

 2017 2018 
 SalesDIFSalesDIF
T1 730.000,00      635.000,00     -95.000,00  
  Jan   91.350,00      136.800,00      45.450,00  
    1        300,00        27.500,00       27.200,00  
    2     5.800,00        13.500,00         7.700,00  
     3   31.000,00         37.100,00         6.100,00  
    4   28.100,00         54.500,00       26.400,00  
    5   10.200,00           4.200,00       - 6.000,00  
    6   15.950,00         15.950,00  

 

I have create the measure DIF:

DIF = 

VAR ActualYear = SELECTEDVALUE(Calendar[Year])
VAR ActualWeek=SELECTEDVALUE(Calendar[Week])

RETURN
[Sales] - CALCULATE([Sales];FILTER(ALL(Calendar); Calendar[Week]=ActualWeek && Calendar[Year]=ActualYear-1))
 
where [Sales]=SUM(SalesTable[Sales]), and the result are this:
 
 2017 2018 
 SalesDIFSalesDIF
T1 730.000,00      635.000,00     635.000,00 
  Jan   91.350,00      136.800,00     136.800,00  
    1        300,00        27.500,00       27.200,00  
    2     5.800,00        13.500,00         7.700,00  
    3   31.000,00         37.100,00         6.100,00  
    4   28.100,00         54.500,00       26.400,00  
    5   10.200,00           4.200,00       - 6.000,00  
    6   15.950,00         15.950,00  

 

It's correct on the week row but it isn't on the subtotals rows for Month and Quarter. What it's wrong?

Thank you very much for all community.

1 ACCEPTED SOLUTION
Microsoft
Microsoft

Hi @Raul,

 

Please refer to the attached sample .pbix file.

 

Regards,

Yuliana Gu

 

Community Support Team _ Yuliana Gu
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
Microsoft
Microsoft

Hi @Raul,

 

Please refer to the attached sample .pbix file.

 

Regards,

Yuliana Gu

 

Community Support Team _ Yuliana Gu
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

Hello @v-yulgu-msft,

One more question about your post. If I want to filter for a year and return the difference with respect to the previous one, without showing the years in columns, how should it be done? Because now if you filter by the year field of the Calendar table, the DIF column returns the same value as the Year column.

Years.JPG

Thanks a lot!

EXCELLENT @v-yulgu-msft!!!!

A complex but an effective solution. Thank you very much!!!!

Helpful resources

Announcements
secondImage

Congratulations!

We are excited to announce the Power BI Super Users!

Microsoft Ignite

Microsoft Ignite with Arun Ulag

Featured Session: Drive Data Culture with Power BI- Vision, Strategy & Roadmap. Register here https://myignite.microsoft.com #MSIgnite #PowerPlatform #Power BI ​

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors