Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
Hello everyone
I have a data table with amounts of money and a date, and I'm struggling to write measures to separate one years amount from another using DAX.
For example (dates are in UK type)
Date Amount
1/8/18 £100
1/9/18 £100
1/10/18 £100
1/11/18 £100
1/12/18 £100
1/1/19 £200
1/2/19 £200
1/3/19 £200
1/4/19 £200
I've tried using CALCULATE(SUM(
but Power BI is refusing to accept the filter as the year.
Can anyone point me in the right direction as to the correct DAX please?
My expected result from above would be 2018 = £500 and 2019 = £800, which I could display in the card visual.
Thanks in advance
Daniel
Solved! Go to Solution.
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
@Anonymous -
Something like:
2018 Results = CALCULATE ( SUM ( TableName[Amount] ), YEAR ( TableName[Date] ) = 2018 )
Proud to be a Super User!
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.
Hi @Anonymous
If you've fixed the issue on your own please kindly share your solution. if the above posts help, please kindly mark it as a solution to help others find it more quickly.thanks!
Thanks everybody. All 3 solutions worked for me! 🙂
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.
@Anonymous -
Something like:
2018 Results = CALCULATE ( SUM ( TableName[Amount] ), YEAR ( TableName[Date] ) = 2018 )
Proud to be a Super User!
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
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
User | Count |
---|---|
102 | |
68 | |
66 | |
52 | |
41 |
User | Count |
---|---|
159 | |
82 | |
65 | |
64 | |
61 |