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
JihyeHeo
Frequent Visitor

DAX: How to display the total MTD sales based on the booked date

Hello, I need your helps for displaying the total sum of the booked sales in this month.

 

I created a Card to display total booked sales and the value of a card is changed based on MTD. 

(FYI, I made a slicer for selecting the displaying month as below)

date.png

 

 

I need to get the sum of MTD sales as follows:

Total booked sales from the first date of the month to the end date of the month(i.e. from 1/1/2020 to 1/31/2020).

For example, I want to display the total sales values booked between 1/1/2020 to 1/31/2020. FYI, the below is a sales table.

sales.png

 

Anyone can help?

 

Thank you,

2 REPLIES 2
Greg_Deckler
Super User
Super User

Well, you can always do something like below. You would want to put this in some visual with your month or filter it.

 

MTD Measure = 
  VAR __Date = MAX([Booked Date])
  VAR __Year = YEAR(__Date)
  VAR __Month = MONTH(__Date)
  VAR __FirstDate = DATE(__Year,__Month,1)
  VAR __LastDate = EOMONTH(__Date,0)
RETURN
  SUMX(
    FILTER(
      'Table',
      [Booked Date] >= __FirstDate && [Booked Date] <= __LastDate
    ),
    [Sales Value]
  )

 


@ 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...
amitchandak
Super User
Super User

If you have Date calendar, then you can try

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-1,MONTH))))
last year MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-12,MONTH))))
last year MTD Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-12,MONTH)))

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 :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

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.