Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Zain_
Frequent Visitor

Show previous period on selecting the current period using date slicer

I want to Calculate a Metric for a Previous Period based on the Current Selected Period.

 

For example: If the user selected a date range of the last 7 days, I want to calculate a Metric for the 7 days before that. It should be dynamic based on the user selection of the date range, not a fixed number.

 

The end goal is to calculate the percentage of change between the 2 values (Metric in the current selected date range and the previous date range).

 

The output should be a single numeric value.

For example:

Current period order count: 100
Previous period order count: 150

1 ACCEPTED SOLUTION

Hi @Zain_ 
what answer you are getting after applying above Dax??

why you have two calendar ??

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

View solution in original post

4 REPLIES 4
Uzi2019
Super User
Super User

Hi @Zain_ 
try below dax

Previous Period  = 
VAR __StartDate = CALCULATE ( MIN ( Dates[Date] ), ALLSELECTED ( Dates[Date] ) )
VAR __EndDate = CALCULATE ( MAX ( Dates[Date] ), ALLSELECTED ( Dates[Date] ) ) 
VAR __Days = DATEDIFF ( __EndDate, __StartDate, DAY ) - 1
RETURN 
CALCULATE ( [Order count], DATEADD ( Dates[Date], __Days, DAY ) )

 

I hope this would get the correct previous period values.


Then you can later divide this by using formla
%change= Divide( [Order count], [Previous Period],0)

 

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!
Zain_
Frequent Visitor

Not Working. This is my DAX formula:

Previous Period =
VAR __StartDate = CALCULATE ( MIN ('Calendar'[Date]), ALLSELECTED ( 'Calendar'[Date]) )
VAR __EndDate = CALCULATE ( MAX ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar'[Date]) )
VAR __Days = DATEDIFF ( __EndDate, __StartDate, DAY ) - 1
RETURN
CALCULATE ( [ACount_Sub], DATEADD ( 'Calendar'[Date], __Days, DAY ) )

I have 2 calendar tables 1 calendar is connected to other visual and how can i connect the other calendar? 

Zain__0-1713899554078.png

I want to make this type of table 

Hi @Zain_ 
what answer you are getting after applying above Dax??

why you have two calendar ??

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!
Zain_
Frequent Visitor

one is for another visual and 2nd calendar is for the visual which I'm trying to create

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.