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
SMG
Frequent Visitor

Using a date slicer to dynamically identify period types in calculated function

Summary: I am trying to use a date range slicer to dynamically update a calculated column in a table.

 

Background: I do a lot of comparisons between a period in time to the corresponding period in time the year prior. So for example, if I have a table that has dates ranging from 1-Jan-20 till today, I want to do a comparison between 15-Nov-23 and 15-Dec-23 to the same period the year prior, so I can compare how I did to the previous year.

That means I need to identify what is This Period [TP] and what is Last Period [LP]. This Period [TP] is defined by the date ranges in a slicer, and Last Period [LP] is automatically calculated as a result, and exclude all values from my card that are not identified as [TP] or [LP].

SMG_0-1704989290505.png

 

SMG_2-1704989609460.png

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @SMG 

 

You can create several measures as follow.

PERIOD = 
VAR _min =
    MIN ( 'Date'[Date] )
VAR _max =
    MAX ( 'Date'[Date] )
VAR _minl =
    DATE(YEAR(_min) - 1, MONTH(_min), DAY(_min))
VAR _maxl =
    DATE(YEAR(_max) - 1, MONTH(_max), DAY(_max))
RETURN
    IF (
        SELECTEDVALUE ( 'Table'[Date] ) >= _min
            && SELECTEDVALUE ( 'Table'[Date] ) <= _max,
        "TP",
        IF (
            SELECTEDVALUE ( 'Table'[Date] )
                >= _minl 
                && SELECTEDVALUE ( 'Table'[Date] )
                    <= _maxl,
            "LP",
            "NA"
        )
    )

 

TP = CALCULATE(SUM('Table'[AMOUNT]), FILTER('Table', 'Table'[PERIOD] = "TP"))

 

LP = CALCULATE(SUM('Table'[AMOUNT]), FILTER('Table', 'Table'[PERIOD] = "LP"))

 

vxuxinyimsft_0-1705052316211.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Yuliax

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @SMG 

 

You can create several measures as follow.

PERIOD = 
VAR _min =
    MIN ( 'Date'[Date] )
VAR _max =
    MAX ( 'Date'[Date] )
VAR _minl =
    DATE(YEAR(_min) - 1, MONTH(_min), DAY(_min))
VAR _maxl =
    DATE(YEAR(_max) - 1, MONTH(_max), DAY(_max))
RETURN
    IF (
        SELECTEDVALUE ( 'Table'[Date] ) >= _min
            && SELECTEDVALUE ( 'Table'[Date] ) <= _max,
        "TP",
        IF (
            SELECTEDVALUE ( 'Table'[Date] )
                >= _minl 
                && SELECTEDVALUE ( 'Table'[Date] )
                    <= _maxl,
            "LP",
            "NA"
        )
    )

 

TP = CALCULATE(SUM('Table'[AMOUNT]), FILTER('Table', 'Table'[PERIOD] = "TP"))

 

LP = CALCULATE(SUM('Table'[AMOUNT]), FILTER('Table', 'Table'[PERIOD] = "LP"))

 

vxuxinyimsft_0-1705052316211.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Yuliax

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

DATE(YEAR(_max) - 1, MONTH(_max), DAY(_max))

Really? Did you ever consider leap years?

sjoerdvn
Super User
Super User

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.