Forum Discussion
QTD MTD Incorrect result
- 4 years agoThanks for your help,I tried but its giving an error now."Parameter is not the correct type"Sample QTD Errors =Var QTDErrorToday =CALCULATE([Total Errors],DATESQTD('Calendar'[Date] =TODAY()))ReturnCOALESCE(QTDErrorToday,0)
- 4 years ago
That's odd - that syntax works for me in a test model.
Does this alternative syntax work, using TREATAS for the filter on today instead of the boolean expression?
Sample QTD Errors = VAR QTDErrorToday = CALCULATE ( [Total Errors], DATESQTD ( TREATAS ( { TODAY () }, 'Calendar'[Date] ) ) ) RETURN COALESCE ( QTDErrorToday, 0 )
Hi Owen,
Yes! that worked well. This was great solution. Thanks for help but now unable to correct this one on same line.
I have Previous Date table which is the duplicate of Calendar table. And this has inactive relationship with Calendar table. This also same problem along with it does not show missing months as zero.
These DAX are so difficult n there are multiple ways to tackle issues.🤔
Regards,
Amol
Hi Amol,
You're welcome 🙂
With this new measure, just confirming, you want it to calculate relative to "today" don't you?
Are you wanting to display it on a card or in a visual with dates?
To at least make it "relative to today" and convert blank to zero, you could try:
Sample Erros 3 months =
VAR ReferenceDate =
TODAY ()
VAR PreviousDates =
DATESINPERIOD (
'Previous Date'[Date],
ReferenceDate,
-3,
MONTH
)
VAR Result =
CALCULATE (
[Total Errors],
REMOVEFILTERS ( 'Calendar' ),
KEEPFILTERS ( PreviousDates ),
USERELATIONSHIP ( 'Calendar'[Date], 'Previous Date'[Date] )
)
RETURN
COALESCE (
Result,
0
)
All I have done is make ReferenceDate equal to TODAY(), and used COALESCE at the final step to return zero if Result is blank.
Regards,
Owen
- amol05124 years agoHelper I
Hi Owen,
I have all cards releative to Today() now. Let's see if Ops has requirement to make it relative to month or Year selection.
This works for me except if we add COALESCE() function then all months are visible from last 3 months. I have removed this function. How we can restrict this?
Regards,
Amol
- OwenAuger4 years agoSuper User
Hi again,
Just coming back to this one - busy week!
I didn't quite understand the issue - could you illustrate how the visual currently appears and how you want it to appear?