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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

DAX calculation with time period selection

Hi, I am new to use DAX, and I want to create two calculation to calculate metrics,

first is to calculation the acculative forecast value based start and end date selected,

second is when date is prior to present then select actual, if later than now then select forecast, and sum the values, and should also consider the date slicer

for example:

start_month_silcer=202206 end_month_silcer=2022010, and current date is 202208,

so the first value(accumulative value of forecast) is 3, 10, 12, 17, 20, which is from 202206 to 202210

the second value is (7+3+2 + 5+3)

null_0-1659433564617.png

Is there a solution to fulfill these two requirements? Thank you!

 

1 ACCEPTED SOLUTION
v-cgao-msft
Community Support
Community Support

Hi @Anonymous ,

 

My test process is as follows:

1. First create a calendar table like this, and create the relationship:

vcgaomsft_0-1659677817392.png

2. Then create these three measures:

Value of forecast = 
VAR _min =
    MIN ( 'Calendar'[Year_Month] )
VAR _max =
    MAX ( 'Calendar'[Year_Month] )
VAR _result =
    CALCULATE (
        SUM ( 'Table'[Forecast] ),
        FILTER (
            'Calendar',
            'Calendar'[Year_Month] >= _min
                && 'Calendar'[Year_Month] <= _max
        ) 
    )
RETURN
    _result
Accumulative value of forecast = 
SUMX (
    FILTER (
        ALLSELECTED ( 'Calendar' ),
        'Calendar'[Year_Month] <= MAX ( 'Calendar'[Year_Month] )
    ),
    [Value of forecast]
)
Actual_Forecast = 
VAR _min =
    MIN ( 'Calendar'[Year_Month] )
VAR _max =
    MAX ( 'Calendar'[Year_Month] )
VAR _today =
    TODAY ()
VAR _yearmonth =
    CALCULATE ( MAX ( 'Calendar'[Year_Month] ), 'Calendar'[Date] = _today )
VAR _actual_total =
    CALCULATE (
        SUM ( 'Table'[Actual] ),
        FILTER (
            'Calendar',
            'Calendar'[Year_Month] >= _min
                && 'Calendar'[Year_Month] <= _yearmonth
        )
    )
VAR _forest_total =
    CALCULATE (
        SUM ( 'Table'[Forecast] ),
        FILTER (
            'Calendar',
            'Calendar'[Year_Month] > _yearmonth
                && 'Calendar'[Year_Month] <= _max
        )
    )
VAR _result = _actual_total + _forest_total
RETURN
    _result

3. Result:

vcgaomsft_1-1659677964297.png

4. The PBIX file is attached for reference.

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

View solution in original post

1 REPLY 1
v-cgao-msft
Community Support
Community Support

Hi @Anonymous ,

 

My test process is as follows:

1. First create a calendar table like this, and create the relationship:

vcgaomsft_0-1659677817392.png

2. Then create these three measures:

Value of forecast = 
VAR _min =
    MIN ( 'Calendar'[Year_Month] )
VAR _max =
    MAX ( 'Calendar'[Year_Month] )
VAR _result =
    CALCULATE (
        SUM ( 'Table'[Forecast] ),
        FILTER (
            'Calendar',
            'Calendar'[Year_Month] >= _min
                && 'Calendar'[Year_Month] <= _max
        ) 
    )
RETURN
    _result
Accumulative value of forecast = 
SUMX (
    FILTER (
        ALLSELECTED ( 'Calendar' ),
        'Calendar'[Year_Month] <= MAX ( 'Calendar'[Year_Month] )
    ),
    [Value of forecast]
)
Actual_Forecast = 
VAR _min =
    MIN ( 'Calendar'[Year_Month] )
VAR _max =
    MAX ( 'Calendar'[Year_Month] )
VAR _today =
    TODAY ()
VAR _yearmonth =
    CALCULATE ( MAX ( 'Calendar'[Year_Month] ), 'Calendar'[Date] = _today )
VAR _actual_total =
    CALCULATE (
        SUM ( 'Table'[Actual] ),
        FILTER (
            'Calendar',
            'Calendar'[Year_Month] >= _min
                && 'Calendar'[Year_Month] <= _yearmonth
        )
    )
VAR _forest_total =
    CALCULATE (
        SUM ( 'Table'[Forecast] ),
        FILTER (
            'Calendar',
            'Calendar'[Year_Month] > _yearmonth
                && 'Calendar'[Year_Month] <= _max
        )
    )
VAR _result = _actual_total + _forest_total
RETURN
    _result

3. Result:

vcgaomsft_1-1659677964297.png

4. The PBIX file is attached for reference.

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.