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

How to get sum of the amount based on previous category value?

I have a table with following columns: fiscal year and the amount (See the table below).

 

TABLE1

Fiscal_YearAmount
2002$100
2002$200
2003$75
2003$95
2003$37
2004$30
2004$90
2005$45
2006$99

 

Also, I have a fiscal year table. This table has One to Many relationship with TABLE1.

 

FY_Table

Fiscal_Year
2002
2003
2004
2005
2006

 

I want to calculate the previous year's amount.

Fiscal_YearAmountLY_Amount
2002$300 

2003

$207$300
2004$120$207
2005$45$120
2006$99$45

 

Following is my trial code which seems to give me all blank in the LY_Amount:

 

measure--> LY_Amount =

var LY_Fiscal_Year = SELECTEDVALUE(FY_Table[Fiscal_Year])-1

return (calculate(sum(TABLE1[Amount]), FILTER(TABLE1, TABLE1[Fiscal_Year] = LY_Fiscal_Year)))

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thanks for all your help. I used the following code.

 

var LY_Fiscal_Year = SELECTEDVALUE(TABLE1[Fiscal_Year])-1

return (calculate(sum(TABLE1[Amount]), all(TABLE1), TABLE1[Fiscal_Year]= LY_Fiscal_Year)))

 

 

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , Try like

 

 

var LY_Fiscal_Year = SELECTEDVALUE(FY_Table[Fiscal_Year])-1

return (calculate(sum(TABLE1[Amount]), FILTER(all(FY_Table), FY_Table[Fiscal_Year]= LY_Fiscal_Year)))

 

Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA

Anonymous
Not applicable

Nope, Nothing. The result is coming all blank

 

Fiscal_YearAmountLY_Amount
2002$300BLANK
2003$207BLANK
2004$120BLANK
2005$45BLANK
2006$99BLANK
Anonymous
Not applicable

Thanks for all your help. I used the following code.

 

var LY_Fiscal_Year = SELECTEDVALUE(TABLE1[Fiscal_Year])-1

return (calculate(sum(TABLE1[Amount]), all(TABLE1), TABLE1[Fiscal_Year]= LY_Fiscal_Year)))

 

 

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.