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

Hi @Archer, we aim to consistently improve the topics being posted on the forum to help you in getting a strong solution faster. While waiting for a response, here are some tips so you can get the most out of the forum and other Enterprise DNA resources.

  • Use the forum search to discover if your query has been asked before by another member.
  • When posting a topic with formula make sure that it is correctly formatted to preformatted text </>.
    image
  • Use the proper category that best describes your topic
  • Provide as much context to a question as possible.
  • Include the masked demo pbix file, images of the entire scenario you are dealing with, screenshot of the data model, details of how you want to visualize a result, and any other supporting links and details.

I also suggest that you check the forum guideline How To Use The Enterprise DNA Support Forum. Not adhering to it may sometimes cause delay in getting an answer.

Please also check the How To Mask Sensitive Data thread for some tips on how to mask your pbix file.

My Revised Measure to acheive Dynamic YTD based on Selected Month
I would be interested to hear of any optimized way of doing the same

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

Many Thanks

Archer