Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
MB2
Frequent Visitor

DatesYTD Equivalent to Use with Direct Query

I am looking for an expression that can substitute for the DatesYTD function in DAX. The DatesYTD function is not compatible with DirectQuery as per here, but I need to use DirectQuery as I am dealing with 50M records and I don't want to use Tabular for this instance. Also, this report is also being saved to Power BI Report Server.

 

I am not completely convinced the issue is with just DirectQuery (as DatesYTD with DirectQuery works fine in Desktop), the issue appears when I open the report via Power BI Report Server: "Function 'DATESYTD' is not supported in DirectQuery mode.
Please try again later or contact support. If you contact support, please provide these details."

 

Here is my DAX formula using the DatesYTD:

**bleep**. Amount (by Year) = CALCULATE(SUM('Product'[Amount]), DATESYTD(Calender[SnapshotDate]), ALLEXCEPT('Product','Product'[ResultsDescription],'Product'[Member],Branches[Division],Branches[Branch]))

I am using the DAX measure to compare cummulative growth by week, with a new line for each year.

 

Thanks

1 ACCEPTED SOLUTION
MB2
Frequent Visitor

Hi DAX0110,

 

I am glad I asked, because I would not have come up with this. You are a genius! The only change that I had to make was to add MAX and correct my poor spelling of 'Calendar'

 

Cummulative Amount (by Year) =
VAR joinDate = MAX( 'Calendar'[SnapshotDate] )
VAR joinYear = YEAR(MAX('Calendar'[SnapshotDate]) )
RETURN CALCULATE(
    SUM('Product'[Amount])
    , FILTER(
        ALL( Calendar )
        , YEAR(Calendar[SnapshotDate]) = joinYear
        && Calendar[SnapshotDate] <= joinDate
        )
    , ALLEXCEPT( 'Product'
        ,'Product'[ResultsDescription]
        ,'Product'[Member]
        ,Branches[Division]
        ,Branches[Branch]
        )
    )

View solution in original post

3 REPLIES 3
DAX0110
Resolver V
Resolver V

Hi @MB2, please try the following to see if it works for you as a replacement for DATESYTD in DirectQuery mode:

 

**bleep**. Amount (by Year) =
VAR joinDate = MAX( 'Product'[JoinDate] )
VAR joinYear = YEAR( joinDate )
RETURN CALCULATE(
    SUM('Product'[Amount])
    , FILTER(
        ALL( Calender )
        , YEAR(Calender[SnapshotDate]) = joinYear
        && Calender[SnapshotDate] <= joinDate
        )
    , ALLEXCEPT( 'Product'
        ,'Product'[ResultsDescription]
        ,'Product'[Member]
        ,Branches[Division]
        ,Branches[Branch]
        )
    )
    

// you'd need to make some mods to this formula: 

//      replace 'Product'[JoinDate] with the actual date column used in the relationship with Calendar

 

MB2
Frequent Visitor

Hi DAX0110,

 

I am glad I asked, because I would not have come up with this. You are a genius! The only change that I had to make was to add MAX and correct my poor spelling of 'Calendar'

 

Cummulative Amount (by Year) =
VAR joinDate = MAX( 'Calendar'[SnapshotDate] )
VAR joinYear = YEAR(MAX('Calendar'[SnapshotDate]) )
RETURN CALCULATE(
    SUM('Product'[Amount])
    , FILTER(
        ALL( Calendar )
        , YEAR(Calendar[SnapshotDate]) = joinYear
        && Calendar[SnapshotDate] <= joinDate
        )
    , ALLEXCEPT( 'Product'
        ,'Product'[ResultsDescription]
        ,'Product'[Member]
        ,Branches[Division]
        ,Branches[Branch]
        )
    )

Greg_Deckler
Super User
Super User

Perhaps you could create a column that is the number of days ago, DATEDIFF and NOW are both supported. Then, you could create your measure by filtering on how many days ago.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors