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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
abhiram342
Microsoft Employee
Microsoft Employee

Calculate MOM based on DateKey

Hi All,

 

I have removed Timestamp (Date) columns and using DateKeys in Fact Tables .  I need to  update few measures from Date to  DateKey. I have below measure (MOM) but facing issue while using DateKey. Is there any workaround (( I need to convert yyyyMMdd to Date while adding to DateAdd Function)

[Total Sales] = CAlCULATE(SUM('FactSales'[Sales]))
MOM Sales : (CALCULATE([Total Sales],ALL('Is Latest'),TREATAS(VALUES('Is Latest'[FactSalesLatestDateKey]),'Date'[DateKey]))/(CALCULATE([Total Sales],ALL('Is Latest'),DATEADD(TREATAS(VALUES('Is Latest'[FactSalesLatestDateKey]),'Date'[DateKey]),-1,MONTH))))-1

 

Note: We keep 2 months daily data and remaining months as monhtly data ( aggregate daily data to single day( last day of month)) in FactSales

 

FactSales:

 

DateKeyProductSales
20220101A100
20220102B200
  
20220201A300
20220202B400

Date: Marked as Date Table ( Date Column as UniqueIdentifier)

DateKeyDate
202201011/1/2022
202201021/2/2022
….. 
202202012/1/2022
202202022/2/2022

Is Latest: this Table tracks Latest datekey in fact tables

Is Latest
FactSalesLatestDateKey
20220202

Relationships:

FactSales * (DateKey) --> 1 Date (DateKey)

FactSales * (DateKey) --> IsLatest(FactSalesLatestDateKey)

 

 

Thanks,

Abhiram

1 REPLY 1
amitchandak
Super User
Super User

@abhiram342 , Date table has column that is date, which you have used to mark it as date table use that

Assuming date is joined with date table

Last Month = CALCULATE(SUM('FactSales'[Sales]), dateadd('DAte'[Date],-1, Month )

 

We should use date from date table.

 

 

Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5b...
To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

 

 

Power BI — Month on Month with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e
https://www.youtube.com/watch?v=6LUBbvcxtKA

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.