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
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

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
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