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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.