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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
maurcoll
Helper III
Helper III

creating a measure that calculates on a different calculation based on a set date

Hi

 

I am trying to create a measure which dependant on date will change the calculation it uses. I have tried using selectedvalue but this doesnt quite work as i am using in another calculation for the last 12 months

example

 

Total =

(if (selectedvalue( 'calendar' [date] >= date (2024,6,1) 
measure 1,

measure 2))

 

This works if i put into a table visual with a date column but i want to be able to use this total in another measure that calculates the total for the last 12 complete months or into a card visual. The data in our source system changed on the 1st June.

This is the measure i use for the last 12 months

Last 12 months = 

VAR maxDate = TODAY() - DAY(TODAY())
VAR minDate = EDATE(TODAY() - DAY(TODAY()), -12)

Return

Total

'Calendar'[Date] <= maxDate && 'Calendar'[Date] > minDate)

 

1 ACCEPTED SOLUTION
Bibiano_Geraldo
Super User
Super User

Hi @maurcoll ,

Here's the updated Measure for Total:

Dynamic Total = 
VAR CutoffDate = DATE(2024, 6, 1)

RETURN
    IF(
        MAX('Calendar'[Date]) >= CutoffDate,
        [Measure 1], -- Use Measure 1 after June 1, 2024
        [Measure 2]  -- Use Measure 2 before June 1, 2024
    )

Now you can calculate the total for the last 12 months dynamically:

Last 12 Months = 
VAR MaxDate = TODAY() - DAY(TODAY()) -- Last day of the previous month
VAR MinDate = EDATE(MaxDate, -12)    -- 12 months before the last day of the previous month

RETURN
    CALCULATE(
        [Dynamic Total],            -- Use the dynamic total measure
        'Calendar'[Date] <= MaxDate &&
        'Calendar'[Date] > MinDate -- Filter dates in the last 12 months
    )

When you use the Dynamic Total measure in a table or matrix, it dynamically switches between Measure 1 and Measure 2 based on the date condition.
When you use the Last 12 Months measure, it applies the date range filter while also dynamically switching between the measures depending on the context of the dates in the filtered period.

View solution in original post

2 REPLIES 2
Bibiano_Geraldo
Super User
Super User

Hi @maurcoll ,

Here's the updated Measure for Total:

Dynamic Total = 
VAR CutoffDate = DATE(2024, 6, 1)

RETURN
    IF(
        MAX('Calendar'[Date]) >= CutoffDate,
        [Measure 1], -- Use Measure 1 after June 1, 2024
        [Measure 2]  -- Use Measure 2 before June 1, 2024
    )

Now you can calculate the total for the last 12 months dynamically:

Last 12 Months = 
VAR MaxDate = TODAY() - DAY(TODAY()) -- Last day of the previous month
VAR MinDate = EDATE(MaxDate, -12)    -- 12 months before the last day of the previous month

RETURN
    CALCULATE(
        [Dynamic Total],            -- Use the dynamic total measure
        'Calendar'[Date] <= MaxDate &&
        'Calendar'[Date] > MinDate -- Filter dates in the last 12 months
    )

When you use the Dynamic Total measure in a table or matrix, it dynamically switches between Measure 1 and Measure 2 based on the date condition.
When you use the Last 12 Months measure, it applies the date range filter while also dynamically switching between the measures depending on the context of the dates in the filtered period.

bhanu_gautam
Super User
Super User

@maurcoll To calculate the total for the last 12 complete months, you can create another measure that uses this Total measure.

 

DAX
TotalLast12Months =
CALCULATE (
[Total],
DATESINPERIOD (
'calendar'[date],
MAX('calendar'[date]),
-12,
MONTH
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.

Top Solution Authors
Top Kudoed Authors