DAX formula to return text string relating to highest sum of values

btreg

New Member
Joined
Feb 29, 2016
Messages
30
I have a table of data, an extract of which looks like this:

[TABLE="class: cms_table_grid, width: 274"]
<tbody>[TR]
[TD]Country
[/TD]
[TD]Product[/TD]
[TD]Office[/TD]
[TD="align: right"]Sales
[/TD]
[/TR]
[TR]
[TD]UK[/TD]
[TD]Shoes[/TD]
[TD]Leeds[/TD]
[TD="align: right"]100[/TD]
[/TR]
[TR]
[TD]UK[/TD]
[TD]Shoes[/TD]
[TD]Leeds[/TD]
[TD="align: right"]100[/TD]
[/TR]
[TR]
[TD]UK[/TD]
[TD]Shoes[/TD]
[TD]Leeds[/TD]
[TD="align: right"]150[/TD]
[/TR]
[TR]
[TD]UK[/TD]
[TD]Shoes[/TD]
[TD]London[/TD]
[TD="align: right"]200[/TD]
[/TR]
[TR]
[TD]UK[/TD]
[TD]Shoes[/TD]
[TD]London[/TD]
[TD="align: right"]340[/TD]
[/TR]
[TR]
[TD]UK[/TD]
[TD]Shoes[/TD]
[TD]London[/TD]
[TD="align: right"]560[/TD]
[/TR]
[TR]
[TD]UK[/TD]
[TD]Shoes[/TD]
[TD]Birmingham[/TD]
[TD="align: right"]800[/TD]
[/TR]
[TR]
[TD]UK[/TD]
[TD]Shoes[/TD]
[TD]Birmingham[/TD]
[TD="align: right"]900[/TD]
[/TR]
[TR]
[TD]UK[/TD]
[TD]Shoes[/TD]
[TD]Birmingham[/TD]
[TD="align: right"]2000[/TD]
[/TR]
</tbody>[/TABLE]


I want to produce a Pivot Table that looks like this:

[TABLE="class: cms_table_grid, width: 146"]
<tbody>[TR]
[TD]Product
[/TD]
[TD="align: right"]Highest Sales
[/TD]
[TD]Office
[/TD]
[/TR]
[TR]
[TD]Shoes[/TD]
[TD="align: right"]3700
[/TD]
[TD="align: right"]Birmingham
[/TD]
[/TR]
</tbody>[/TABLE]


Thans to help from an earlier thread, I am using the following DAX formula to return the value of the Birmingham office's sales, as Birmingham has the highest sales:

=MAXX ( VALUES ( Sales[Office] ), CALCULATE ( SUM ( Sales[Sales] ) ) )

Is there a DAX formula that will return the text string 'Birmingham', based on the fact this office has the highest sales, as established by the above formula?
Any help much appreciated.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi
Try
Code:
=FIRSTNONBLANK(
    SUMMARIZE(TOPN(1, 
        SUMMARIZE('Sales','Sales'[Office], "sales amount", SUM('Sales'[Sales])),
        [sales amount], 0
        ), 'Sales'[Office]
    ),1 
)
But are you sure that it is always a single office with the highest sales?
Regards, Andrey.
 
Last edited:
Upvote 0
Brilliant, does exactly what I needed it to, thank you!

I guess you mean that two (or more) offices could be tied for the highes sales value? This is possible but sufficiently unlikely that I think the analysis is still useful.
 
Upvote 0
A follow-up question if anyone can help....

How would I modify the above formula to return the name of the office with the 3rd highest sales, for example?
 
Upvote 0
Apologies, I didn't realise this same formula could be used in the context of providing me with the office name as a text string.

However, I am struggling to get this to work in practice. I'm getting the error message "A table of multiple values was supplied where a single value was epxected" - could this be tied values causing the error? If so, how do I add FIRSTNONBLANK to the above? My attempt is causing an error message.
 
Upvote 0
Thanks for the example - your help is much appreciated. I will compare with my own model and figure out what the problem is.
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top