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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
luke050
Frequent Visitor

Calculate Monthly SUM - YOY, SamePeriodLastYear issue

the point is that I want to calculate the sum of sales for the current month and see the result from the year before

 

input data:

devFactSprzedaz[Data] -  column with date

devFactSprzedaz[Sprzedaż netto] - sales  column

devDimArtykul[Nazwa Magazynu] - column with stores list used for filtering specific stores

 

so I have two measures. The first one to calculate the sales value for the current month and this one work well all the time:

 

MTD = TOTALMTD(SUM(devFactSprzedaz[Sprzedaż netto]),devFactSprzedaz[Data])  

 

and another to calculate same but year ago:

 

MTD LY = CALCULATE(TOTALMTD(SUM('devFactSprzedaz'[Sprzedaż netto]),'devFactSprzedaz'[Data]),SAMEPERIODLASTYEAR('devFactSprzedaz'[Data]))

 

without any filters, everything works ok !

 

the problem is when applied filters using devDimArtykul[Nazwa Magazynu]  in right pane:

 

obraz.png

 

if I choose some stores from the list. the value of my second measure displays such an error:

 

obraz.png

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

Hi @luke050,

 

You need to create a date table, and use the date table in the [MTD LY] measure. Time intelligence calculations should be based on a date table.





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

Proud to be a Super User!




View solution in original post

4 REPLIES 4
luke050
Frequent Visitor

Ok so i created Date Table:

 

obraz.png

 

now the error does not appear, but the output for my  MTD LY is incorrect, I get too large amount. and I don't know where it comes from because the measure looks ok

 

updated Measure:

 

 

MTD LY = CALCULATE(TOTALMTD(SUM('devFactSprzedaz'[Sprzedaż netto]),'devFactSprzedaz'[Data]),SAMEPERIODLASTYEAR(DateKey[Date]))

 

 

 

as far as I know it should work even if I use a smart date and then I don't need this date table but the result is the same:

 

Smart Date Measure

 

 

MTD LY = CALCULATE(TOTALMTD(SUM('devFactSprzedaz'[Sprzedaż netto]),'devFactSprzedaz'[Data]),SAMEPERIODLASTYEAR('devFactSprzedaz'[Data].[Date]))

 

 

 

 

in both cases my measure returns 12.72M and it show sum for period 2020-12-01   to 2020-12-31 but why??

also  I calculated desired period manually and it should be : 3.94M

where am i making a mistake ?

 

obraz.png

v-jingzhang
Community Support
Community Support

Hi @luke050 

Some Time Intelligence functions expect a continuous distinct date column to work with. A common and recommended practice is to use a Date table. Refer to below links to understand more about date table and modify your model accordingly.

https://radacad.com/do-you-need-a-date-dimension

https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

 

Regards,
Community Support Team _ Jing Zhang

Nathaniel_C
Super User
Super User

Hi @luke050 , @DataInsights ,
Also, to use Time Intelligence functions the date table must be contiguous and cover the whole period that you are calculating.
Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel

 





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

Proud to be a Super User!




DataInsights
Super User
Super User

Hi @luke050,

 

You need to create a date table, and use the date table in the [MTD LY] measure. Time intelligence calculations should be based on a date table.





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

Proud to be a Super User!




Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.