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
h4_dkj
Helper I
Helper I

Calculate YTD, TP, LYTD

Hi

 

I have a base table that shows me kpi values for several business measures.

It looks like this, you get the idea I hope:

IDYearMonthTypenameValue
120211FinanceCost111
220211SalesIncome222
120212FinanceCost123
320212HMSInjuries1
220212SalesIncome234
120213FinanceCost145
32021

3

HMSInjuries2
320213SalesIncome231
120201FinanceCost123
120202FinanceCost150
120203FinanceCost199
320203HMSInjuries1

 

Now what I need to solve is to create a Value_YTD, Value_TP, Value_LYTD, Value_LTP, Diff_YTD(5) for month 3

KPIValue_YTDValue_TPValue_LYTDValue_LTPDiff_YTD(%)
1 - Finance - cost379145572199 
2 - Sales - Income687231   
3 - HMS - Injuries3211 

 

How do i solve this?

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

Hi @h4_dkj ,

 

Please consider taking calendar tables into account for future modeling so that more and more powerful time-intelligent functions can be used. 

 

First create a new calculated column.

ID_Type_Name = 'Table'[ID] & " - " & 'Table'[Type] & " - " & 'Table'[name]

vcgaomsft_0-1656481565240.png

Then create these measures.

Value_YTD = 
CALCULATE ( SUM ( 'Table'[Value] ), 'Table'[Year] = MAX ( 'Table'[Year] ) )
Value_TP = 
CALCULATE (
    SUM ( 'Table'[Value] ),
    FILTER (
        'Table',
        'Table'[Year] = MAX ( 'Table'[Year] )
            && 'Table'[Month] = MAX ( 'Table'[Month] )
    )
)
Value_LYTD = 
CALCULATE ( SUM ( 'Table'[Value] ), 'Table'[Year] = MAX ( 'Table'[Year] ) - 1 )
Value_LTP = 
CALCULATE (
    SUM ( 'Table'[Value] ),
    FILTER (
        'Table',
        'Table'[Year] = MAX ( 'Table'[Year] ) - 1
            && 'Table'[Month] = MAX ( 'Table'[Month] )
    )
)
Diff_YTD(%) = 
VAR _rate =
    DIVIDE ( [Value_YTD] - [Value_LYTD], [Value_YTD] )
VAR _result =
    IF ( [Value_LYTD] = BLANK (), BLANK (), _rate )
RETURN
    _result

vcgaomsft_1-1656481749084.png

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

2 REPLIES 2
v-cgao-msft
Community Support
Community Support

Hi @h4_dkj ,

 

Please consider taking calendar tables into account for future modeling so that more and more powerful time-intelligent functions can be used. 

 

First create a new calculated column.

ID_Type_Name = 'Table'[ID] & " - " & 'Table'[Type] & " - " & 'Table'[name]

vcgaomsft_0-1656481565240.png

Then create these measures.

Value_YTD = 
CALCULATE ( SUM ( 'Table'[Value] ), 'Table'[Year] = MAX ( 'Table'[Year] ) )
Value_TP = 
CALCULATE (
    SUM ( 'Table'[Value] ),
    FILTER (
        'Table',
        'Table'[Year] = MAX ( 'Table'[Year] )
            && 'Table'[Month] = MAX ( 'Table'[Month] )
    )
)
Value_LYTD = 
CALCULATE ( SUM ( 'Table'[Value] ), 'Table'[Year] = MAX ( 'Table'[Year] ) - 1 )
Value_LTP = 
CALCULATE (
    SUM ( 'Table'[Value] ),
    FILTER (
        'Table',
        'Table'[Year] = MAX ( 'Table'[Year] ) - 1
            && 'Table'[Month] = MAX ( 'Table'[Month] )
    )
)
Diff_YTD(%) = 
VAR _rate =
    DIVIDE ( [Value_YTD] - [Value_LYTD], [Value_YTD] )
VAR _result =
    IF ( [Value_LYTD] = BLANK (), BLANK (), _rate )
RETURN
    _result

vcgaomsft_1-1656481749084.png

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

SpartaBI
Community Champion
Community Champion

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.

Top Solution Authors