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
KIlekun
New Member

PREVIOUS PERIOD VALUE

Hi Guys, I am trying to calculate the previous period GHI (attached image in the post). The "Global Hunger Index" Column is a measure i created to calculate the global average of individual countries aggregated within the year they were recorded, while the "Previous Period GHI" is meant to return the previous period Value of the "Global Hunger Index". But the issue is that since the time intervals are not equal, this makes the DATEADD function not return the values accordingly (i.e i want the 17.51 to be just beside 16.79). So, how do i calculate the Previous Value with a dynamic date interval? I hope you guys understand my problem statement😢Error 1.jpg

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @KIlekun 
Please try

Previous Period GHI =
VAR CurrentYear =
    MAX ( 'Table'[End of Year] )
VAR T1 =
    ALLSELECTED ( 'Table'[End of Year] )
VAR T2 =
    ADDCOLUMNS (
        T1,
        "@GHI",
            VAR ThisYear = 'Table'[End of Year]
            RETURN
                CALCULATE ( [Global Hunder Index], 'Table'[End of Year] = ThisYear )
    )
VAR T3 =
    FILTER ( T2, 'Table'[End of Year] < CurrentYear && [@GHI] <> BLANK () )
VAR T4 =
    TOPN ( 1, T3, 'Table'[End of Year] )
RETURN
    IF ( [Global Hunder Index] <> BLANK (), MAXX ( T4, [@GHI] ) )

View solution in original post

2 REPLIES 2
KIlekun
New Member

@tamerj1 OH MY GOD it worked sooooo perfectly. Thank you

tamerj1
Super User
Super User

Hi @KIlekun 
Please try

Previous Period GHI =
VAR CurrentYear =
    MAX ( 'Table'[End of Year] )
VAR T1 =
    ALLSELECTED ( 'Table'[End of Year] )
VAR T2 =
    ADDCOLUMNS (
        T1,
        "@GHI",
            VAR ThisYear = 'Table'[End of Year]
            RETURN
                CALCULATE ( [Global Hunder Index], 'Table'[End of Year] = ThisYear )
    )
VAR T3 =
    FILTER ( T2, 'Table'[End of Year] < CurrentYear && [@GHI] <> BLANK () )
VAR T4 =
    TOPN ( 1, T3, 'Table'[End of Year] )
RETURN
    IF ( [Global Hunder Index] <> BLANK (), MAXX ( T4, [@GHI] ) )

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.