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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Davidkm
Frequent Visitor

Find year where is Max profit as sum profit by year

Hi, 

I would need a measure that will give me back the year when the biggest profit was. Data as table below.

 

Thx

 

David

 

 

IDDateProfit
11.1.20205
21.2.20204

3

5.10.2020

6

4

6.5.2018

8

5

6.4.2019

9
 

...

 

 

1 ACCEPTED SOLUTION
Davidkm
Frequent Visitor

I found resolution:

year_with_max_profit = 

var distinc_table = ADDCOLUMNS(KEEPFILTERS(VALUES('Table'[Date].[Year])), "profit", CALCULATE(COUNTA('Table'[id])))
var maxobj = MAXX(
	distinc_table,
	CALCULATE(COUNTA('Table'[id]))
    )

return CALCULATE(MIN('Table'[Year]), FILTER(distinc_table , [profit] = maxobj))

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi  @Davidkm ,

Here are the steps you can follow:

1. Create calculcated column.

Year = YEAR('Table'[Date])

Month = MONTH('Table'[Date])

2. Create measure.

Max_Month =
var _1=
MAXX(ALL('Table'),'Table'[Profit])
return CALCULATE(MAX('Table'[Year]),FILTER('Table','Table'[Profit]=_1))

3. Result.

v-yangliu-msft_0-1605834996539.jpeg

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

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

 

Hi Liu, 

the assignment is different. I wanted to know the year where the amount of profit for the whole year is the largest.

D.

 

Davidkm
Frequent Visitor

I found resolution:

year_with_max_profit = 

var distinc_table = ADDCOLUMNS(KEEPFILTERS(VALUES('Table'[Date].[Year])), "profit", CALCULATE(COUNTA('Table'[id])))
var maxobj = MAXX(
	distinc_table,
	CALCULATE(COUNTA('Table'[id]))
    )

return CALCULATE(MIN('Table'[Year]), FILTER(distinc_table , [profit] = maxobj))
amitchandak
Super User
Super User

@Davidkm , with help from date table take max of profit

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"))
This year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31"))
Last year 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))
//Only year vs Year, not a level below


This Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi, 

this is not what I want. I need get year and not sum profit. In my example i need get 2020.

thx

 

David

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.