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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Grouping years with dax for forecast

Hi,

 

I need to group my forecast count for all years before 2021 into the 2021 bucket. and then I will need to use this measure in a bar chart. 

 

So basically in the sample below I need to sum the values between 2015 - 2021 as 2021.

 

YearForecast
20155
20163
20174
20185
20191
20203
20215
20226
20238

Is this possible with dax?

 

Thank you

1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @Anonymous 

Thanks for reaching out to us.

I write a measure for your reference, 

Total before 2021 =
VAR _startYear =
    CALCULATE ( MIN ( 'Table'[Year] ), ALL ( 'Table' ) )
VAR _thisYear =
    YEAR ( TODAY () )
RETURN
    IF (
        MIN ( 'Table'[Year] ) = _thisYear,
        CALCULATE (
            SUM ( 'Table'[Forecast] ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[Year] <= _thisYear
                    && 'Table'[Year] >= _startYear
            )
        )
    )

result

vxiaotang_0-1634618741002.png

 

if you need more help, please @ me.

 

 

Best Regards,

Community Support Team _Tang

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

View solution in original post

2 REPLIES 2
v-xiaotang
Community Support
Community Support

Hi @Anonymous 

Thanks for reaching out to us.

I write a measure for your reference, 

Total before 2021 =
VAR _startYear =
    CALCULATE ( MIN ( 'Table'[Year] ), ALL ( 'Table' ) )
VAR _thisYear =
    YEAR ( TODAY () )
RETURN
    IF (
        MIN ( 'Table'[Year] ) = _thisYear,
        CALCULATE (
            SUM ( 'Table'[Forecast] ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[Year] <= _thisYear
                    && 'Table'[Year] >= _startYear
            )
        )
    )

result

vxiaotang_0-1634618741002.png

 

if you need more help, please @ me.

 

 

Best Regards,

Community Support Team _Tang

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

MFelix
Super User
Super User

Hi @Anonymous 

 

Try the following measure:

 

Forecast = CALCULATE (SUM(Table[Forecast), FILTER(ALL(Table[Year]), Table[Year] >= 2015 && Table[Year] <= 2021))

 

This may need some adjustments depending on yout model setup.


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.