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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
jackalmf
New Member

Issues with TOTALYTD & previous year calculations

Hi Power BI community,

 

I wrote some queries which I believe were working correctly last year but in the new year these do not seem to function as intended. There is a calendar table I created over the course of last year as well as using the DocDate from tables.

 

To explain the premise I am wanting to show total sales year to date (YTD)  minus any credits year to date.

I am then using 2 additional queries to calculate the same for the previous year to date and then comparing the 2 to see % increase/decrease.

 

These queries seemed to be working okay last year but after rolling over into the new year I am now not so sure.

 

My queries as follows:

 

TotalYTD-Credits = [TotalYTDexcVAT] - [TotalCreditsYTDExcVAT]

TotalYTDexcVAT = TOTALYTD(CALCULATE(SUM(OINV[DocTotal]) - SUM(OINV[VatSum])), OINV[DocDate])
TotalCreditsYTDExcVAT = TOTALYTD(
    CALCULATE(SUM(ORIN[DocTotal]) - SUM(ORIN[VatSum])),
    ORIN[DocDate]
    )
 
TotalPYTD-Credits = [TotalPYTDexcVAT] - [TotalCreditsPYTDexcVAT]
TotalPYTDexcVAT = TOTALYTD(
    CALCULATE(SUM(OINV[DocTotal]) - SUM(OINV[VatSum])),
    SAMEPERIODLASTYEAR('Calendar Table'[Date])
)
TotalCreditsPYTDexcVAT = TOTALYTD(
    CALCULATE(SUM(ORIN[DocTotal]) - SUM(ORIN[VatSum])),
    SAMEPERIODLASTYEAR(ORIN[DocDate])
)
 
To calculate the difference my query is:
 
TotalPrYR%-Credits = ([TotalYTD-Credits] - [TotalPYTD-Credits]) / [TotalPYTD-Credits]
 
The calendar table creation code as follows:
 
Calendar Table =
    VAR MinDate = YEAR ( MIN ( OINV[DocDate]) )
    VAR MaxDate = YEAR ( MAX ( OINV[DocDate]) )
    RETURN
    ADDCOLUMNS(
        FILTER (
   
        CALENDARAUTO(),
        YEAR ([Date] ) >= MinDate &&
        year ([Date] ) <= MaxDate
           ),

    "Year", YEAR([Date]),
    "Quarter", FORMAT ([Date], "\QQ" ),
    "Month", FORMAT ( [Date], "mmmm" ),
    "Month Number", MONTH ([Date])
)
 
Any help appreciated, perhaps there is something I am missing in my understanding here! 🙂 
 
Many thanks
1 REPLY 1
v-xiandat-msft
Community Support
Community Support

Hi @jackalmf ,

Could you please give me the sample data and the expected results, thank you very much.

Best Regards,

Xianda Tang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.