Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.