SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Can't get any DAX YTD functions to perform correctly


Can't get any DAX YTD functions to perform correctly

Author
Message
alistair.brown
alistair.brown
Valued Member
Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)

Group: General Forum Members
Points: 60 Visits: 57
Hi,

I am struggling to make any progress with time intelligence functions in SSAS Tabular (or indeed in PowerPivot). I have even created a very simple setup to try to get this to work, but to know avail. Here are some details:

2 tables:
Dates dimension table, with all dates I need, with PK as Date.
Fact table, containing Date as FK, a value called AccountNumber as a dimension and a field containing Amount. These are joined, and the Date table is marked as a date table. Date is not unique in the fact table, since there is a secondary dimension.

First method I tried is simple: =TOTALYTD(sum([Amount]);Dates[Date]). This executes, but is identical to the Amount field (i.e. no aggregation by dates)

Second method I tried is similar and gives the same result: =CALCULATE(SUM([Amount]);DATESYTD(Dates[Date]))

I also tried using the ALL filter on the Dates table: =CALCULATE(SUM([Amount]);DATESYTD(Dates[Date]);ALL(Dates))

I can get it to work for the AccountNumber dimension by including an ALLEXCEPT clause: =CALCULATE(SUM([Amount]);DATESYTD(Dates[Date]);ALLEXCEPT(Budget_Values;Budget_Values[AccountNumber]))

So when I slice by AccountNumber it works fine. But what if I want to slice by another dimension (once I add them)? Or even by two dimensions at the same time? As far as I can see, I would need to create the YTD logic for every slicing dimension and every combination of slicing dimensions!

I want a method that allows me to calculate YTD values for a given measure, regardless of how I am slicing. I have got this working fine in MDX, but need to get it working in DAX to allow integration with PowerView etc.

Any thoughts?
alistair.brown
alistair.brown
Valued Member
Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)

Group: General Forum Members
Points: 60 Visits: 57
OK, I've solved it myself. In the interests of sharing this with anyone else facing the same problem here is what was going wrong.

I was trying to create the YTD calculation as a row level function, where it should of course be an aggregate function and therefore be entered at the bottom of the table rather than in a row.

So my function is something similar to:
=TOTALYTD(sum([Amount]);'Dates'[Date])


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search