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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
agd50
Helper V
Helper V

Dax Assistance - YTD unless Q1 then previous Year YTD

how would you do calculation for YTD, unless it's Q1 of a new year then give the total YTD of last year.

How would that look?

TIA

1 ACCEPTED SOLUTION
v-heq-msft
Community Support
Community Support

Hi @agd50 ,

Here some steps that I want to share, you can check them if they suitable for your requirement.

Here is my test data:

vheqmsft_0-1704938933353.png

1.Create a measure

YTD_Conditional = 
VAR CurrentQuarter = QUARTER(TODAY())
VAR CurrentYear = YEAR(TODAY())
RETURN
IF(
    CurrentQuarter = 1,
    CALCULATE(
        SUM('Table'[Amount]),
        FILTER(
            ALL('Table'),
            YEAR('Table'[Date]) = CurrentYear - 1
        )
    ),
    TOTALYTD(
        SUM('Table'[Amount]),
        'Table'[Date]
    )
)

2.Final output
Please note that today() is 2024/01/11

vheqmsft_1-1704939200163.png

 

Best regards

Albert He

 

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

View solution in original post

2 REPLIES 2
v-heq-msft
Community Support
Community Support

Hi @agd50 ,

Here some steps that I want to share, you can check them if they suitable for your requirement.

Here is my test data:

vheqmsft_0-1704938933353.png

1.Create a measure

YTD_Conditional = 
VAR CurrentQuarter = QUARTER(TODAY())
VAR CurrentYear = YEAR(TODAY())
RETURN
IF(
    CurrentQuarter = 1,
    CALCULATE(
        SUM('Table'[Amount]),
        FILTER(
            ALL('Table'),
            YEAR('Table'[Date]) = CurrentYear - 1
        )
    ),
    TOTALYTD(
        SUM('Table'[Amount]),
        'Table'[Date]
    )
)

2.Final output
Please note that today() is 2024/01/11

vheqmsft_1-1704939200163.png

 

Best regards

Albert He

 

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

gadielsolis
Super User
Super User

Hello,

 

Please try the following DAX:

 
        IF(QUARTER(SELECTEDVALUE('Table'[Date]))=1,
        CALCULATE(SUM('Table'[Amount]),PREVIOUSYEAR('Table'[Date])),
        CALCULATE(SUM('Table'[Amount]),DATESYTD('Table'[Date])))

if this works please mark this message as solution, thank you.

Helpful resources

Announcements
Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors