cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
Super User III
Super User III

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
Super User IV
Super User IV

@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



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Super User III
Super User III

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

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
secondImage

Happy New Year from Power BI

This is a must watch for a message from Power BI!

December Update

Check it Out!

Click here to read more about the December 2020 Updates!

Community Blog

Check it Out!

Click here to read the latest blog and learn more about contributing to the Power BI blog!

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.