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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
dgeg
Frequent Visitor

help with calculation

Hello!

 

Looking for help writing a formula:

 

Year over year comparison by month.

The oldest data I have is Jan 2023.

 

I have the following so far:

YoY Var =
IF(
    ISFILTERED('Calendar'[Date]),
    ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column."),
    VAR __PREV_MONTH = CALCULATE([Monthly Spend], DATEADD('Calendar'[Date].[Date], -12, MONTH))
    RETURN
        CALCULATE([Monthly Spend] - __PREV_MONTH)
)
 
 
dgeg_0-1713292935329.png

 

I do not want YoY Var to populate for 2023 because there is no historical data to compare to and I do not want 2024 YoY Var to populate in months that have not happened yet.

 

 

Any help woul dbe appreciated. Thank you!

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

Hi @dgeg ,

 

You can try formula like below:

 

YoY Var =
IF (
    ISFILTERED ( 'Calendar'[Date] ),
    ERROR ( "Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column." ),
    VAR __CURR_MONTH = [Monthly Spend]
    VAR __PREV_YEAR_MONTH =
        CALCULATE (
            [Monthly Spend],
            FILTER (
                ALL ( 'Calendar' ),
                YEAR ( 'Calendar'[Date] )
                    = YEAR ( MAX ( 'Calendar'[Date] ) ) - 1
                    && MONTH ( 'Calendar'[Date] ) = MONTH ( MAX ( 'Calendar'[Date] ) )
            )
        )
    RETURN
        IF (
            YEAR ( MAX ( 'Calendar'[Date] ) ) > 2023
                && MONTH ( MAX ( 'Calendar'[Date] ) ) > MONTH ( TODAY () ),
            BLANK (),
            IF (
                NOT ( ISBLANK ( __PREV_YEAR_MONTH ) ),
                __CURR_MONTH - __PREV_YEAR_MONTH,
                BLANK ()
            )
        )
)

 

 

vkongfanfmsft_0-1713774628781.png

 

Best Regards,
Adamk Kong

 

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

2 REPLIES 2
v-kongfanf-msft
Community Support
Community Support

Hi @dgeg ,

 

You can try formula like below:

 

YoY Var =
IF (
    ISFILTERED ( 'Calendar'[Date] ),
    ERROR ( "Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column." ),
    VAR __CURR_MONTH = [Monthly Spend]
    VAR __PREV_YEAR_MONTH =
        CALCULATE (
            [Monthly Spend],
            FILTER (
                ALL ( 'Calendar' ),
                YEAR ( 'Calendar'[Date] )
                    = YEAR ( MAX ( 'Calendar'[Date] ) ) - 1
                    && MONTH ( 'Calendar'[Date] ) = MONTH ( MAX ( 'Calendar'[Date] ) )
            )
        )
    RETURN
        IF (
            YEAR ( MAX ( 'Calendar'[Date] ) ) > 2023
                && MONTH ( MAX ( 'Calendar'[Date] ) ) > MONTH ( TODAY () ),
            BLANK (),
            IF (
                NOT ( ISBLANK ( __PREV_YEAR_MONTH ) ),
                __CURR_MONTH - __PREV_YEAR_MONTH,
                BLANK ()
            )
        )
)

 

 

vkongfanfmsft_0-1713774628781.png

 

Best Regards,
Adamk Kong

 

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

Greg_Deckler
Super User
Super User

@dgeg TryBetter Year Over Year Change - Microsoft Fabric Community

 

You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.