Forum Discussion
DAX expression
- 6 years ago
Hi Anonymous
You could use a calendar table and a slicer to select the year you want (probably the best option). Or you can just create measures
Measure = VAR Year_ = 2018 // Change as required RETURN CALCULATE ( SUM ( Table1[Date] ), FILTER ( ALL ( Table1[Date] ), YEAR ( Table1[Date] ) = Year_ ) )Please mark the question solved when done and consider giving kudos if posts are helpful.
Cheers

- 6 years ago
Anonymous -
Something like:
2018 Results = CALCULATE ( SUM ( TableName[Amount] ), YEAR ( TableName[Date] ) = 2018 ) - 6 years ago
Hello Anonymous
Have you considered adding a date table to your model? This will let you group your data by year / month / quarter etc. You can create a date table by entering this DAX code in a "New table" measure.
Dates = VAR DateRange = CALENDARAUTO() RETURN ADDCOLUMNS( DateRange, "Year",YEAR ( [Date] ), "Month", FORMAT ( [Date], "mmmm" ), "MonthNum", MONTH ( [Date] ), "Month Year", FORMAT ( [Date], "mmm-yyyy"), "MonthYearNum", YEAR ( [Date] ) * 100 + MONTH ( [Date] ), "Quarter Year", "Q" & FORMAT ( [Date], "q-yyyy" ), "QtrYearNum", YEAR ( [Date] ) * 100 + VALUE ( FORMAT ( [Date], "q" ) ) )Then you link the Date field from the Dates table to the Date field in your data table. Once connected you can use all the fields in the date table as filters and groupings of your data.
Hello Anonymous
Have you considered adding a date table to your model? This will let you group your data by year / month / quarter etc. You can create a date table by entering this DAX code in a "New table" measure.
Dates =
VAR DateRange = CALENDARAUTO()
RETURN
ADDCOLUMNS(
DateRange,
"Year",YEAR ( [Date] ),
"Month", FORMAT ( [Date], "mmmm" ),
"MonthNum", MONTH ( [Date] ),
"Month Year", FORMAT ( [Date], "mmm-yyyy"),
"MonthYearNum", YEAR ( [Date] ) * 100 + MONTH ( [Date] ),
"Quarter Year", "Q" & FORMAT ( [Date], "q-yyyy" ),
"QtrYearNum", YEAR ( [Date] ) * 100 + VALUE ( FORMAT ( [Date], "q" ) )
)
Then you link the Date field from the Dates table to the Date field in your data table. Once connected you can use all the fields in the date table as filters and groupings of your data.