Forum Discussion
Issue with TotalMTD Calculation.
- 1 year ago
Hi AThakur1 ,
Try the below DAX,
MTD Consumption =
var_CurrentMonth = MONTH(TODAY())
var_CurrentYear = YEAR(TODAY())
var_Hasdatathismonth =
CALCULATE(COUNTROWS(Consumption),
FILTER(
Consumption,
MONTH(Consumption[Consumption Date]) = _CurrentMonth &&
YEAR(Consumption[Consumption Date]) = _CurrentYear
)
) > 0
RETURN
IF(Hasdatathismonth, TOTALMTD(SUM(Consumption[Qty Consumed]), 'Date'[Date]),BLANK()
It checks if the item has any consumption in April, and only then it shows MTD otherwise shows blank.
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks and Regards,
Chaithra E.
Hello AThakur1 ,
TOTALMTD works based on the current filter context. So, if your item isn't actively filtered in a visual or slicer, Power BI computes the total for all items for the month-to-date. You need to filter the calculation by item if you're expecting it per item, or clarify the context in your measure.
If you want to compute MTD for a selected item only:
MTDConsumption =
CALCULATE(
TOTALMTD(
SUM(Consumption[Qty Consumed]),
Consumption[Consumption Date]
),
ALLSELECTED(Consumption[Item]) -- or filter by a specific item
)
If this solved your issue, please mark it as the accepted solution. ✅
anilelmastasi ,Thank you for reply!
Below is the desired output table.However, both dax calcuating total from the previous months (whichever is the last available month )for the highlited yellow rows, as these items not consumed in current month their data not availabel for Apr'25 in the dataset.
If i check MTD/YTD total it's correct, but in rows its cehcking data for all the items from item master.
Bleow data is coming from three tables:
Item no from item master.
Stock from Stock & consumption from consumption.
Also,created calander used below formula but same result. :