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
newbie_but_conf
Helper II
Helper II

Get dynamic max for all years

Hi,

 

I would like to plot a max line in my line chart for all months. It should ignore my slicer for year and always show the max sale amount for each month in the year. Which means if I select only 2024, it should still show max for each month from any year in my table. 
I would like it to also be dynamic and show max of selected area and/or industry.. 

I know I have to make a measure for each year and use a contains etc to have more measures (max and for each year)..

 

Just trying to think how I can create a max line as well. I've tried using sumarize like this:

 

Max sales = 
VAR tbl = SUMMARIZE(
    sheet1, 
    sheet1[Month],
    sheet1[Year],
    "Total sales", SUM(sheet1[sale]))

Return
    CALCULATE(
        MAXX(tbl, [Total sales]),
        ALL(sheet1[year])
    )

 

 But this is still filtering when i select a year.. 

Can anyone help me with this?

I've attached a pbix file.

 

https://file.io/cVyRhzm3KNgZ

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @newbie_but_conf ,

 

Try the following code:

Max sales = VAR MaxMonth = MAX(sheet1[Month])
		VAR tbl =

		SUMMARIZE(
			FILTER(
				ALL(sheet1),
				sheet1[Month] = MaxMonth
			),
			sheet1[Year],
			sheet1[Month],
			"Total sales", MAX(sheet1[sale])
		)


		RETURN

			MAXX(
				CALCULATETABLE(
					tbl,
					REMOVEFILTERS(sheet1[Year]),
					sheet1[Month] = MAX(sheet1[Month])
				),
				[Total sales]
			)

 

PBIX attached


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

2 REPLIES 2
v-huijiey-msft
Community Support
Community Support

Hi @newbie_but_conf ,

 

Your solution is great, @MFelix . It worked very well! Here's another idea I'd like to share with you for reference.

 

I worked very hard on this case and there was no solution at that time, so I hope you'll take a look at mine as well.

 

There are some problems with the data when you use Year directly from the original table.

vhuijieymsft_0-1715159283018.png

 

Create a date table and extract the year and month:

 

Calendar = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))

Year = YEAR('Calendar'[Date])

Month = MONTH('Calendar'[Date])

 

 

Create two measures to calculate Sum of Sales and Monthly Maximum:

 

Sales = 
VAR _Slicer = SELECTEDVALUE('Calendar'[Year])
VAR _currentDate = MAX('Table'[Date])
RETURN
IF(YEAR(MAX('Table'[Date]))=_Slicer,SUM('Table'[Sale]),IF(_Slicer=BLANK(),SUM('Table'[Sale])))
MaxSales = 
VAR _currentdate = MAX('Table'[Date])
RETURN
CALCULATE(MAX('Table'[Sale]),FILTER(ALLSELECTED('Table'),'Table'[Date]=_currentdate))

 

 

Create the Slicer using the Year of the Calendar table, leaving the other two Slicers unchanged.

 

Use Line Chart, Year Slicer choose 2024, the page effect is as follows:

vhuijieymsft_1-1715159363302.png

 

On this basis Area Slicer selects 1 and the page effect is as follows:

vhuijieymsft_2-1715159363303.png

vhuijieymsft_3-1715159382440.png

 

The pbix file is attached.

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

MFelix
Super User
Super User

Hi @newbie_but_conf ,

 

Try the following code:

Max sales = VAR MaxMonth = MAX(sheet1[Month])
		VAR tbl =

		SUMMARIZE(
			FILTER(
				ALL(sheet1),
				sheet1[Month] = MaxMonth
			),
			sheet1[Year],
			sheet1[Month],
			"Total sales", MAX(sheet1[sale])
		)


		RETURN

			MAXX(
				CALCULATETABLE(
					tbl,
					REMOVEFILTERS(sheet1[Year]),
					sheet1[Month] = MAX(sheet1[Month])
				),
				[Total sales]
			)

 

PBIX attached


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.