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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
archerjayden
Helper I
Helper I

YTD with SelectedValue of Year Month Slicer

Hi ,

I would like dax to calculate YTD based on SelectedValue of Year Month Slicer. I need to show Current Period, YTD and Full Current Year in three different matrices.

I am implementing Calc Groups to reduce plethora of measures from being created.

Users need a slicer to dynamically switch Calc Groups of Current Period, YTD and Full Year.

So when Year Month 2020-P10(October) is Selected then I need YTD to calculate from Jan to Oct of 2020.

Similarly when Year Month 2019-October is Selected then I need YTD to calculate from Jan to Oct of 2019.

here is my Current Period Calc

CP Measure =

CALCULATE (

SELECTEDMEASURE (),

FILTER (

ALLSELECTED ( fact_table ),

fact_table [type] = “ACTUAL”

),

FILTER (

fact_table,

fact_table[YearMonth]

= SELECTEDVALUE ( ‘dim_date’[[YearMonth] )

)

)
YTD Measure = 
CALCULATE (
SELECTEDMEASURE (),
FILTER (
ALLSELECTED ( fact_table ),
fact_table [type] = "ACTUAL"
),
DATESYTD( fact_table[Date])
)


When nothing is selected on Slicer I get YTD Values but when Slicer has selection of Year Month then CP & YTD shows same.

Please guide how I can achieve this requirement

Thanks,
Archer

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

That's not really what YTD means. (No dates are involved, only complete months). All you need to do is

- get the slicer selection

- get all dates in the same year and less than or equal the selection

- get the value aggregate for that filter.

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@archerjayden , if you have date and using date table, Why don't you use time intelligence

 

examples

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))

 

Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
lbendlin
Super User
Super User

That's not really what YTD means. (No dates are involved, only complete months). All you need to do is

- get the slicer selection

- get all dates in the same year and less than or equal the selection

- get the value aggregate for that filter.

You are absolutely right @lbendlin 

Thank you for your guidance at the right time! 

My Revised Measure to acheive Dynamic YTD based on Selected Month 

Many Thanks

Archer

YTD Measure = 
CALCULATE (
SELECTEDMEASURE (),
FILTER (
ALL ( fact_table ),
fact_table [type] = "ACTUAL"
),
FILTER (
ALL ( fact_table ),
fact_table[YearPeriod]
>= LEFT(SELECTEDVALUE(dim_date[YearPeriod]),4) & " 01"
&& fact_table[YearPeriod] 
<= SELECTEDVALUE ( 'dim_date'[YearPeriod] )
)
)

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.