cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
featleyd Helper III
Helper III

DAX expression

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

3 ACCEPTED SOLUTIONS

Accepted Solutions
Super User III
Super User III

Re: DAX expression

Hi @featleyd 

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  Datanaut

  

View solution in original post

Super User I
Super User I

Re: DAX expression

@featleyd -

Something like:

2018 Results = 
CALCULATE (
    SUM ( TableName[Amount] ),
    YEAR ( TableName[Date] ) = 2018
)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

Super User IV
Super User IV

Re: DAX expression

Hello @featleyd 

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.

View solution in original post

5 REPLIES 5
Super User III
Super User III

Re: DAX expression

Hi @featleyd 

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  Datanaut

  

View solution in original post

Super User I
Super User I

Re: DAX expression

@featleyd -

Something like:

2018 Results = 
CALCULATE (
    SUM ( TableName[Amount] ),
    YEAR ( TableName[Date] ) = 2018
)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

Super User IV
Super User IV

Re: DAX expression

Hello @featleyd 

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.

View solution in original post

Community Support
Community Support

Re: DAX expression

Hi @featleyd 

 

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!

 

 

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.
Highlighted
featleyd Helper III
Helper III

Re: DAX expression

Thanks everybody. All 3 solutions worked for me! 🙂

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Join THE global Microsoft Power Platform event series.

Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors