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

MTD Not Working Properly

Table:

DateItem
1-AugApple
1-AugOrange
1-AugBanana
2-AugApple
2-AugOrange
3-AugApple

 

There are 2 slicers:
Slicer1: Date: Single Selection
Slicer2: Item: Multiple Selection

DAX: To determine MTD count
TOTALMTD(COUNT(Table['Item']), DATEMTD(ALLSELECTED(Table['Date'])))

 

Case1: Slicer1: 2-Aug & Slicer2: Apple and Orange

DAX returns 4 (Correct)

 

Case2: Slicer1: 3-Aug & Slicer2: Apple and Orange

DAX returns 3. Expected output is 5. (3 Apples on 1/2/3Aug and 2 Oranges on 1/2Aug)

 

Seeking advice here as I am struggling hard throughout the day. How to get the MTD DAX to cater for 2 oranges in the past (1/2 Aug)?

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @Nigel99 

 

You can try the following methods.
New table:

Date = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))

vzhangti_0-1693488276362.png

Measure = Var _table=CALCULATETABLE(VALUES('Table'[Item]),FILTER('Table',[Item]<>BLANK()))
Return
CALCULATE(COUNT('Table'[Item]),FILTER(ALL('Table'),[Date]<=MAX('Date'[Date])&&[Item] in _table))

vzhangti_1-1693488309027.pngvzhangti_2-1693488320834.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

6 REPLIES 6
v-zhangti
Community Support
Community Support

Hi, @Nigel99 

 

You can try the following methods.
New table:

Date = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))

vzhangti_0-1693488276362.png

Measure = Var _table=CALCULATETABLE(VALUES('Table'[Item]),FILTER('Table',[Item]<>BLANK()))
Return
CALCULATE(COUNT('Table'[Item]),FILTER(ALL('Table'),[Date]<=MAX('Date'[Date])&&[Item] in _table))

vzhangti_1-1693488309027.pngvzhangti_2-1693488320834.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Thanks!! It worked!!

Greg_Deckler
Community Champion
Community Champion

@Nigel99 Try:

Measure = 
  VAR __Today = TODAY()
  VAR __StartOfMonth = DATE( YEAR( __Today ), MONTH( __Today ), 1 )
  VAR __Table = FILTER( 'Table', [Date] >= __StartOfMonth && [Date] <= __Today )
  VAR __Return = COUNTROWS( __Table )
RETURN
  __Return

You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...

 

Also:



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler  Thanks for prompt reply. I afraid that this did not work out. The DAX is dependent on date selection from date slicer instead of today date.

@Greg_Deckler  Able to advise further? Thank you in advance 

@Nigel99 Just replace TODAY with MAX('Table'[Date]).



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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.