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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
spartanboy
Helper II
Helper II

Select Current and Prior Period when the Date is text format

Hello - 

The slicer is set to "Single Select". The "TIME_FRAME" column can contains actual dates or text (like, 2022Q1, 2022Q2, 2022H1, 2022H2). If the user selects 2022Q2, the measure should result in 2022Q1. What needs to be changed in my attempt below?

 

Evetually, I would like to calculate change % from the selected time with prior time.

 

 

Calculate_PRIOR_PERIOD = 
VAR _selectedDates = VALUES(F_COST[TIME_FRAME])
var _currentperiod = maxx(ALLSELECTED(F_COST[TIME_FRAME]),F_COST[TIME_FRAME])
var _priorperiod = ??? - "here the logic should be to provide result as 2022Q1"
RETURN _priorperiod

 

 TIA

3 REPLIES 3
v-luwang-msft
Community Support
Community Support

Hi @spartanboy ,

Test the below:

test =
VAR maxvalue =
    CALCULATE (
        MAX ( D_DATE_TIME[Rank] ),
        FILTER (
            ALL ( D_DATE_TIME ),
            'D_DATE_TIME'[Rank] < MAX ( 'D_DATE_TIME'[Rank] )
        )
    )
RETURN
    CALCULATE (
        MAX ( D_DATE_TIME[TIME_FRAME] ),
        FILTER ( ALL ( D_DATE_TIME ), D_DATE_TIME[Rank] = maxvalue )
    )

 

vluwangmsft_0-1659347353084.pngvluwangmsft_1-1659347361716.png

Did I answer your question? Mark my post as a solution!


Best Regards

Lucien

Anonymous
Not applicable

@spartanboy 
Assume if you have dimension table as QTR and data something like below for quarters in wholenumber which has relationship with your fact table where the measures are coming from.
I have created the rank for each quarter using dax.

Rank = RANKX(Qtr,Qtr[Qtr No],,ASC,Dense)

Mohan1029_0-1658986035087.png

Then, I have created a standalone calculated table as QTR_Slicer from the above table using below dax.

This table is used for only to select the quarters using slicer.

Mohan1029_1-1658986231204.png

then use the below measure to calcualte the prior quarter values.

CALCULATE([Your Measure]),
Qtr[Rank]  =  SELECTEDVALUE(Qtr_Slicer[Rank])-1))

 

Accept the solution if that works for you.

 

Thanks,

Mohan V.

 

@Anonymous Thanks for assistance!

 

First I created a table that contains unique quarters and rank, and use this 'TIME_FRAME' as a slicer.

spartanboy_1-1659014656264.png

 

 

Calculate_CURRENT_PERIOD = 
VAR _selectedDates = VALUES(D_DATE_TIME[TIME_FRAME])
var _currentperiod = maxx(ALLSELECTED(D_DATE_TIME[TIME_FRAME]),D_DATE_TIME[TIME_FRAME])
RETURN _currentperiod

 

 

With your final measure i am getting a rank of the prior period. How to get the PRIOR_PERIOD i.e. 2022Q1 when slicer selection is 2022Q2?

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors