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
Anonymous
Not applicable

How to display a measure of same period for last serveral years when a specific date is filtered?

I have a problem and It is very difficult for me.

So, I ask for help.

 

I have to display a measure of same period for last several years when a specific date is filtered.

 

I have tables below:

 

FactReal

DateReal
2017-01-0115
2017-01-0239
2017-01-035
2018-01-0136
2018-01-0210
2018-01-0335
2018-01-0426
2019-01-0150
2019-01-0228
2019-01-0349

 

FactTarget

DateTarget
2017-01-0170
2017-02-0171
2018-01-01120
2018-02-0198
2019-01-01140
2019-02-01147

 

DimDate

DateYear
2017-01-01Y2017
2017-01-02Y2017
2017-01-03Y2017
2017-01-04Y2017
2017-01-05Y2017
2017-01-06Y2017
2017-01-07Y2017
2017-01-08Y2017
2017-01-09Y2017
2019-12-28Y2019
2019-12-29Y2019
2019-12-30Y2019
2019-12-31Y2019

 

And I have measures:

RealYTD = CALCULATE(SUM('FactReal'[Real]), DATESYTD('DimDate'[Date])
TargetYTD = CALCULATE(SUM('FactTarget'[Target]), DATESYTD('DimDate'[Date])
Progress Rate = DIVIDE([RealYTD]), [TargetYTD]))

 

I want to display [Progress Rate] of YTD for last 3 years when a specific date of DimDate is filtered.

 

For example,
Visualization have to display [Progress Rate] of YTD for 2017, [Progress Rate] of YTD for 2018, [Progress Rate] of YTD for 2019 when I choose "2019-01-02" 

Progress Rate.png

 

I think there should be a table like this:


FactAggregation

DateSubDateRealYTDTargetYTDProgress Rate
2019-01-012017-01-01157021.43%
2019-01-012018-01-013612030.00%
2019-01-012019-01-015014035.71%
2019-01-022017-01-02547077.14%
2019-01-022018-01-024612038.33%
2019-01-022019-01-027814055.71%
2019-01-032017-01-03597084.29%
2019-01-032018-01-038112067.50%
2019-01-032019-01-0312714090.71%

 

I think have to have a relationship between FactAggregation[Date] and DimDate[Date]
And then give a FactAggregation[SubDate] column to x-axis of visualization.

And give a FactAggregation[Progress Rate] column to value of visualization.

 

The date slicer must be a date column in DimDate because other visualizations are filtered by this slicer.

 

I think it, but I don't know how to create a table like FactAggregation
So, I am suffering from this problem.

Please help me.

 

P.S. If you have a other better solution, please suggest for me 

 

Thank you

2 REPLIES 2
Anonymous
Not applicable

Hi, 

You have two ways to do this

1. Using calculation Groups:

You could do this using the below mentioned link 

https://www.sqlbi.com/articles/introducing-calculation-groups/

2. Using SELECTEDVALUE DAX function

 

Progress Rate_2017= VAR CURRENT_YEAR-2= YEAR(SELECTEDVALUE(DATE COLUMN))-2

Var current_date= SELECTEDVALUE(DATE COLUMN FILTER)

 

RETURN CALCULATE(SUMX(FILTER(TABLE, YEAR=CURRENT_YEAR-2),REAL),DATESINPERIOD(DATES,CURRENT_DATES,-2,YEAR)/CALCULATE(SUMX(FILTER(TABLE, YEAR=CURRENT_YEAR-2),TARGET),DATESINPERIOD(DATES,CURRENT_DATES,-2,YEAR))

 

REPEAT THE SAME FOR 2018 (CURRENT YEAR-1). AND FOR CURRENT YEAR (2019) JUST LEAVE IT AS SELECTEDVALUE IN THE VAR STATEMENT 

 

DO ACCEPT AS SOLUTION IF IT SOLVES YOUR PROBLEM

kentyler
Solution Sage
Solution Sage

Consider adding a column for the 2 other years you are interested in to the dimDate table. Then when someone selects a year, the previous year and the year before that will be available to your Dax code directly in the dimDate table. That should make it much easier to do the calculations against them.





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


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.