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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Giada90
Helper III
Helper III

make a formula with a date dynamic

Hi,

I need to make this formula dynamic based on today's date, any help?

Ricavi_BDG_FY 2 = IF(average(Aggregato[FY])=2022, CALCULATE([Ricavi_BDG],DATESBETWEEN('Date'[Date],Date(2022,1,1),DATE(2022,12,2)),ALL('Date'[Date])), IF(AVERAGE(Aggregato[FY])=2021, CALCULATE([Ricavi_BDG], DATESBETWEEN('Date'[Date],Date(2021,1,1),date(2021,12,2)),ALL('Date'[Date])),IF(AVERAGE(Aggregato[FY])=2020, CALCULATE([Ricavi_BDG], DATESBETWEEN('Date'[Date], date(2020,1,1),date(2020,12,2)),all('Date'[Date])),0)))
 
Thanks
1 ACCEPTED SOLUTION

@Giada90 , You can try this:-

Ricavi_BDG_FY 2 =
VAR _current_year =
    YEAR ( TODAY () )
RETURN
    IF (
        AVERAGE ( Aggregato[FY] ) = _current_year,
        CALCULATE (
            [Ricavi_BDG],
            DATESBETWEEN (
                'Date'[Date],
                DATE ( _current_year, 1, 1 ),
                DATE ( _current_year, 12, 2 )
            ),
            ALL ( 'Date'[Date] )
        ),
        IF (
            AVERAGE ( Aggregato[FY] ) = _current_year - 1,
            CALCULATE (
                [Ricavi_BDG],
                DATESBETWEEN (
                    'Date'[Date],
                    DATE ( ( _current_year - 1 ), 1, 1 ),
                    DATE ( ( _current_year - 1 ), 12, 2 )
                ),
                ALL ( 'Date'[Date] )
            ),
            IF (
                AVERAGE ( Aggregato[FY] ) = _current_year - 2,
                CALCULATE (
                    [Ricavi_BDG],
                    DATESBETWEEN (
                        'Date'[Date],
                        DATE ( ( _current_year - 2 ), 1, 1 ),
                        DATE ( ( _current_year - 2 ), 12, 2 )
                    ),
                    ALL ( 'Date'[Date] )
                ),
                0
            )
        )
    )

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

View solution in original post

4 REPLIES 4
Samarth_18
Community Champion
Community Champion

Hi @Giada90 ,

 

Could you help us to understand which date you wanted to replace with todays date?

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Hi @Samarth_18 , I mean current year

@Giada90 , You can try this:-

Ricavi_BDG_FY 2 =
VAR _current_year =
    YEAR ( TODAY () )
RETURN
    IF (
        AVERAGE ( Aggregato[FY] ) = _current_year,
        CALCULATE (
            [Ricavi_BDG],
            DATESBETWEEN (
                'Date'[Date],
                DATE ( _current_year, 1, 1 ),
                DATE ( _current_year, 12, 2 )
            ),
            ALL ( 'Date'[Date] )
        ),
        IF (
            AVERAGE ( Aggregato[FY] ) = _current_year - 1,
            CALCULATE (
                [Ricavi_BDG],
                DATESBETWEEN (
                    'Date'[Date],
                    DATE ( ( _current_year - 1 ), 1, 1 ),
                    DATE ( ( _current_year - 1 ), 12, 2 )
                ),
                ALL ( 'Date'[Date] )
            ),
            IF (
                AVERAGE ( Aggregato[FY] ) = _current_year - 2,
                CALCULATE (
                    [Ricavi_BDG],
                    DATESBETWEEN (
                        'Date'[Date],
                        DATE ( ( _current_year - 2 ), 1, 1 ),
                        DATE ( ( _current_year - 2 ), 12, 2 )
                    ),
                    ALL ( 'Date'[Date] )
                ),
                0
            )
        )
    )

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

thanks!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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