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
Yin
Frequent Visitor

How to calculate sameperiodlastyear ?

Dear all,

 

I have a table that I want to calculate sameperiodlastyear value, but since there are multi sameperiods in time column, the dax returns blank.  My formula is like: Value_sameperiodlastyear = CALCULATE(sum[value],SAMEPERIODLASTYEAR([monthyear])). 

 

My table example is as following:

monthyearcustomerValueValue_sameperiodlastyear
1/1/2017A1111111
1/1/2017B2222222
1/1/2017C3333333
1/1/2016A111 
1/1/2016B222 
1/1/2016C333 

Column "Value_sameperiodlastyear" is the result I want, by using the first three columns. 

 

Do you guys know how to write the correct formula? Many thanks!

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@Yin

 

If you use the same formula as a MEASURE it will work

Probably you are using it as Calculated Column

 

= CALCULATE(sum(TableName[Value]),SAMEPERIODLASTYEAR(TableName[monthyear]))

 

If you have to use a Calculated Column use this

 

Column =
CALCULATE (
    SUM ( TableName[Value] ),
    ALLEXCEPT ( TableName, TableName[customer] ),
    SAMEPERIODLASTYEAR ( TableName[monthyear] )
)

Regards
Zubair

Please try my custom visuals

View solution in original post

1 REPLY 1
Zubair_Muhammad
Community Champion
Community Champion

@Yin

 

If you use the same formula as a MEASURE it will work

Probably you are using it as Calculated Column

 

= CALCULATE(sum(TableName[Value]),SAMEPERIODLASTYEAR(TableName[monthyear]))

 

If you have to use a Calculated Column use this

 

Column =
CALCULATE (
    SUM ( TableName[Value] ),
    ALLEXCEPT ( TableName, TableName[customer] ),
    SAMEPERIODLASTYEAR ( TableName[monthyear] )
)

Regards
Zubair

Please try my custom visuals

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.