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
trying
Frequent Visitor

Dax YTD Calculation over multiple years

Hi everyone,

 

i have a problem with a dax formula and i hope you can help me.

 

I want to have a line chart which displays ytd sales for the last 4 years, based on a slicer where i want to select a month up to which the ytd value should be calculated to. Meaning when i select the month 06 for 2021 i want to have in the y axis of the line chart the following values:

 

for 2021 --> the ytd sales value for 2021 until the month 06 

for 2020 -->the ytd sales value for 2020 until the month 06

for 2019 -->the ytd sales value for 2019 until the month 06

for 2018 -->the ytd sales value for 2018 until the month 06

 

In the x axis i would then drop the year from my calendar do display the evolution of the ytd sales.

 

Thanks in advance for your help and KR,

Daniel

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

Hi @trying ,

 

Is this you want?

vchenwuzmsft_0-1662451436621.gif

 

If yes, you need create a measure like the following:

Measure =
VAR _ytddate =
    FILTER ( ALLSELECTED ( 'Table' ), [Date].[MonthNo] <= MAX ( 'Month'[index] ) )
VAR _ytddate_c =
    FILTER (
        _ytddate,
        [Date] <= MAX ( 'Table'[Date] )
            && [Date].[Year] = MAX ( 'Table'[Date].[Year] )
    )
RETURN
    IF (
        SELECTEDVALUE ( 'Month'[index] ) < MAX ( 'Table'[Date].[MonthNo] ),
        BLANK (),
        SUMX ( _ytddate_c, [Value] )
    )

 


Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

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

3 REPLIES 3
v-chenwuz-msft
Community Support
Community Support

Hi @trying ,

 

Is this you want?

vchenwuzmsft_0-1662451436621.gif

 

If yes, you need create a measure like the following:

Measure =
VAR _ytddate =
    FILTER ( ALLSELECTED ( 'Table' ), [Date].[MonthNo] <= MAX ( 'Month'[index] ) )
VAR _ytddate_c =
    FILTER (
        _ytddate,
        [Date] <= MAX ( 'Table'[Date] )
            && [Date].[Year] = MAX ( 'Table'[Date].[Year] )
    )
RETURN
    IF (
        SELECTEDVALUE ( 'Month'[index] ) < MAX ( 'Table'[Date].[MonthNo] ),
        BLANK (),
        SUMX ( _ytddate_c, [Value] )
    )

 


Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

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

ValtteriN
Super User
Super User

Hi,

Here is one way to do this:
Data:

ValtteriN_0-1662123889756.png

ValtteriN_2-1662124827210.png





Relationship:

ValtteriN_1-1662124009542.png


Dax:

Measure 19 = CALCULATE(SUM('Table (7)'[Value]),DATESYTD('Calendar'[Date]))
Measure 20 = CALCULATE([Measure 19],SAMEPERIODLASTYEAR('Calendar'[Date]))
Measure 21 = CALCULATE([Measure 20],SAMEPERIODLASTYEAR('Calendar'[Date]))

The idea is to user SAMEPERIODLASTYEAR for each additional year you want to see to past.

End result:
ValtteriN_4-1662125086775.png

 

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





 





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

Proud to be a Super User!




Hi,

 

first off all thanks for the reply and your effort!

 

Unfortunately this wont solve my issue. I wanted to have one single measure that can do the trick. Is this possible?

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