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

Time Functions

Hi,

@amitchandak @Ashish_Mathur 

I have data Amount and Date in a table and wanted to calculate some time functions. I dont want to use any calendar table here. I derived Year and Month from the date field and using it for filters.

 

I do have filters like Year and Month. When I select Year 2022 and Month APRIL

 

1) Selected Month and Year: I just used SUM(Amount) -- I am getting correct results.

 

2) Same selected Month and Year but Last Year:

CALCULATE(SUM(Amount),SAMEPERIODLASTYEAR(Date))  --- not sure why this is not giving correct results. I suppose to get 2021 APRIL data but it is showing BLANK.
 
3) YTD: My financial year starts from APRIL to MARCH when I selected 2022 and APRIL. I suppose to see 2022 APRIL to 2023 March.  not sure how to get this done.
 
Last Year YTD: When I select 2022 APRIL then I supposed to see 2021 APRIL to 22 MARCH. not sure how to get this done.
 
Appreciated your support.
 
Thanks,
1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @Thimma ,

 

Please try:

Last Year Same Month = 
CALCULATE(SUM('Table'[Amount]),FILTER(ALL('Table'),YEAR([Date])=SELECTEDVALUE('Table'[Date].[Year])-1 && MONTH([Date])=MAX('Table'[Date].[MonthNo])))
FY = IF(MONTH(MAX('Table'[Date]))<4, YEAR(MAX('Table'[Date]))-1 , YEAR(MAX('Table'[Date])) )
FY Sum = CALCULATE(SUM('Table'[Amount]),FILTER(ALL('Table'),[FY]=MAXX('Table',[FY]))) 
Last Year YTD = CALCULATE(SUM('Table'[Amount]),FILTER(ALL('Table'),[FY]=MAXX('Table',[FY])-1))

Eyelyn9_0-1655797072633.png

 


Best Regards,
Eyelyn Qin
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

3 REPLIES 3
v-eqin-msft
Community Support
Community Support

Hi @Thimma ,

 

Please try:

Last Year Same Month = 
CALCULATE(SUM('Table'[Amount]),FILTER(ALL('Table'),YEAR([Date])=SELECTEDVALUE('Table'[Date].[Year])-1 && MONTH([Date])=MAX('Table'[Date].[MonthNo])))
FY = IF(MONTH(MAX('Table'[Date]))<4, YEAR(MAX('Table'[Date]))-1 , YEAR(MAX('Table'[Date])) )
FY Sum = CALCULATE(SUM('Table'[Amount]),FILTER(ALL('Table'),[FY]=MAXX('Table',[FY]))) 
Last Year YTD = CALCULATE(SUM('Table'[Amount]),FILTER(ALL('Table'),[FY]=MAXX('Table',[FY])-1))

Eyelyn9_0-1655797072633.png

 


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

Yes it worked, much appreciated your support.

Ashish_Mathur
Super User
Super User

Hi,

Why do you not want to create a Calendar Table?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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.