How to construct DAX measure to calculate sum of YTD value for specific month?

Here we have FactTable grouped by months. FactTable is filled with both Actual data and Forecast data. The only way to know when Actual end is information in table [Cut of date] in column [End of YTD]. In table [Cut of date] in column [End of YTD] – it is a single value table – we have the interesting chosen month, for which we want to see the calculation of YTD. In our case it is March.

How to construct DAX measure to calculate sum of YTD value for specific month?

Here we have FactTable grouped by months. FactTable is filled with both Actual data and Forecast data. The only way to know when Actual end is information in table [Cut of date] in column [End of YTD]. In table [Cut of date] in column [End of YTD] – it is a single value table – we have the interesting chosen month, for which we want to see the calculation of YTD. In our case it is March. FactTable is updated irregularly every month with usually one month delay. There is no way of linking it to time functions like TODAY because of irregular update.

We would like to have a correct value of YTD displayed in yellow Card Visual for the month [End of YTD]. When we click on the slicer on "2018-03" we get almost what we want – correct value of 66 in the yellow Card. However this solution is not automatic. I want to see correct value automatically when the [End of YTD] month changes, in our case to April or then to May. I do not want it done by user.

I pursued the deer in various ways:

1. By using FILTER function in DAX measures. But it seems that the FILTER function is to harsh. It is applied to fact table first, selecting only one month, and then calculating YTD value wrongly. So if there would be any option for forcing order of calculation and filtering, there would be hope.
2. I tried SWITCH function to display proper result for specific month and 0 or null for other months. Although I succeed in this, I was not able to take advantage of it. When it came to filtering I was as hopeless as before. BTW I would be able to make it if SWITCH produced totals at the end of the table, but it does not. Surprisingly.
3. I put some hopes in RELATED function to display proper results in the [Cut off date] table. I have not walk out of the fog so far. Dec 22, 2020 in Power BI 1,731 views

## 1 answer to this question.

If you use the date column from `FactTable`, when you apply a filter on the date, it will filter on the fact records which is in March, and then do the calculation afterwards, hence the result `33`.

If you use the one from `Calendar`, when you apply a filter on it, it filters the records on `Calendar` (which you want to show in the chart), so the underlying calculation will still remain intact.

A working example:

`Calendar = CALENDAR(DATE(2010, 1, 1), DATE(2020, 12, 31))` I suggest you to change the calculations of the measures to avoid missing values in some cases:

``````Total = SUM(FactTable[Value])
MTD = TOTALMTD([Total], 'Calendar'[Date])
YTD = TOTALYTD([Total], 'Calendar'[Date])
``````  answered Dec 22, 2020 by
• 65,850 points

## How to rename a column using DAX in Power BI?

Hi Ramya, I found these two function that ...READ MORE

## How to customize the report for different users in power BI?

There are different ways to achieve this. 1. ...READ MORE

## How to get month name from month number in Power BI?

You can use: MonthName = FORMAT(DATE(1, [Num], 1), ...READ MORE

## Understanding the DAX CALCULATE function

Using the CALCULATE function makes the DAX perform a context ...READ MORE

## DAX Userelationship function

You need a way for the measure ...READ MORE

## How to restart running total column with Power BI Desktop DAX?

This is not only a running total ...READ MORE