Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
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
Solved! Go to Solution.
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.
@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
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] )
)
)