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
Anonymous
Not applicable

Datediff v SPLY

Hi all,

 

Essentially, what I'm trying to do is calculate the premium that has been written, and exclude the premium that occurred as a result of the cancellation of the policy but I'm getting a really big weird number for SPLY and current year looks okay. 

 

Measure = SUM(Table[Premium]) - CALCULATE(SUM(Table[Premium]) / 365 * (365 - SUM(Table[DateDiff])), Table[Cancel Date]>0 )

 

Where DateDiff = Calculated Column = DATEDIFF( Table[Inception Date], Table[Cancel Date], DAY) 

 

Policy NumberInception DateCancel DatePremiumDateDiff
A01/01/201930/06/2019$100Days: Incept - Cancel
B01/02/201925/10/2019$300As above
C05/01/202010/03/2020$500As above
D04/02/2020-$600As above

 

When I do the SPLY formula, I'm doing

SPLY = CALCULATE ( Measure , SAMEPERIODLASTYEAR ( Calendar ( date ) )

 

Is this correct, or am I doing it wrong because I'm getting an incorrect huge number for 2019, but 2020 looks okay. 

 

Thanks for any help. 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi. Thanks everyone for your suggestions.

 

I found out the issue wasn't in the SPLY formula, where I simply used sameperiodlastyear calc. The Datediff formula was giving me grief and apparently you can't SUM the datediff, when I used AVERAGE datediff, it gave me the appropriate number and the measure then worked. 

View solution in original post

4 REPLIES 4
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

If you take the answer of someone, please mark it as the solution to help the other members who have same problems find it more quickly. If not, let me know and I'll try to help you further. Thanks.

 

Best Regards

Allan

Anonymous
Not applicable

Hi. Thanks everyone for your suggestions.

 

I found out the issue wasn't in the SPLY formula, where I simply used sameperiodlastyear calc. The Datediff formula was giving me grief and apparently you can't SUM the datediff, when I used AVERAGE datediff, it gave me the appropriate number and the measure then worked. 

v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

You may try the following measure.

 

SPLY = 
var _currentyear = YEAR(MAX('Table'[Inception Date]))

return
CALCULATE(
    [Measure],
    FILTER(
        ALLSELECTED('Table'),
        YEAR('Table'[Inception Date]) = _currentyear-1
    )
)

 

 

Here is the result.

a1.png

 

If I misunderstand your thought, please show me your expected result. Thanks.

 

Best Regards

Allan

 

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

amitchandak
Super User
Super User

Please note the measure need row context. Please check this file on how you can take datediff and keep the context. there are 4 ways.

 

As they are single table , so you can leave one where copy them to common table

https://www.dropbox.com/s/y47ah38sr157l7t/Order_delivery_date_diff.pbix?dl=0

 

try this for years. Examples

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(('Date'[Date]),"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
Last YTD complete Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
Last to last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))
2 Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-2,Year))

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @

Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Proud to be a Datanaut Connect on Linkedin

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