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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
matdax
Frequent Visitor

MAX value of summarized values based type per month

Hello. 

 

I have a scenario in a table where I have a values column, a type of values column, location, and date period. The value being presented is not a contributory value but the total result.

 

See below as an example

 

yearmonthtypelocationvalue
2024augusttotal dogschicago50
2024julytotal dogstoronto60
2024augusttotal dogstoronto40
2024julytotal dogschicago10
2023augusttotal dogschicago50
2023julytotal dogstoronto80
2024augusttotal catschicago10
2024julytotal catstoronto10
2023augusttotal catschicago10

 

matdax_0-1726699475746.png

 

What I am trying to do, is add up the total dogs (disregarding location) for each month, and then display the max number of dogs (type column) per period. Each month should only have one entry per location per type. However if someone errornously enters 2 values, the max value for that month should be used.

 

Expected result: august 2024 = 90 dogs
For the year of 2024 = 90 dogs as august is the higher number

For July 2024 = 70 dogs

 

Would love some help!

13 REPLIES 13
Anonymous
Not applicable

Hi @matdax ,

 

I made simple samples and you can check the results below:

vtianyichmsft_0-1726724530027.png

Total = CALCULATE(SUM('Table'[value]),ALLEXCEPT('Table','Table'[type],'Table'[year],'Table'[month]))    

 

An attachment for your reference. Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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

lbendlin
Super User
Super User

 

However if someone errornously enters 2 values, the max, or last value for that month should be used.

 

Power Query does not know what you mean by "last".  You need to provide your own sort column.

 

lbendlin_0-1726704816385.png

 

Thanks! Almost perfect

 

Can a filter be included within the measure to only return this data for total dogs?

Not sure what you are asking. How to use filters in Power BI?

No I realise I could apply the filter to the visual this is attached to or to the report, but for this purpose I want the data in the column itself to exclusively have the dogs. I tried adjusting the filter as part of var c, but it didn't work

I tried adjusting the filter as part of var c, but it didn't work

That's the right spot.  Show what you tried.

Thanks again for your help, here's what I have

 

Max count =
var a = SUMMARIZE('Table',[year],[month],[location])
var b = ADDCOLUMNS(a,"i",CALCULATE(max('Table'[Index])))
var c = FILTER('Table',[Index] in SELECTCOLUMNS(b,[i]) && 'Table'[type] == "total dogs")
var d = SUMMARIZE(c,[year],[month])
var e = ADDCOLUMNS(d,"ct",CALCULATE(sum('Table'[value])))
RETURN MAXX(e,[ct])
 
Displaying the value on its own table still shows 100, vs 90
 
matdax_0-1727045387208.png

 

Try this

 

var c = FILTER('Table',[Index] in SELECTCOLUMNS(b,[i]) && [type] = "total dogs")

Same result - it returns 100 for August, whilst it should report 90

Cute.  Need to investigate it a bit more.  In the meantime you can cheat by using a visual filter

 

lbendlin_0-1727050278591.png

 

Thanks! Yeah it's got me scratching my head

SachinNandanwar
Super User
Super User

What value should be displayed for cats, or should the records for cats be discarded?



Regards,
Sachin
Check out my Blog

We may want to acheive the same result as per dogs for the cat data, but it isn't neccesary. For the purposes of what I'm after here, cats can be disregraded thank you

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.