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:

Country
ProductOfficeSales
UKShoesLeeds100
UKShoesLeeds100
UKShoesLeeds150
UKShoesLondon200
UKShoesLondon340
UKShoesLondon560
UKShoesBirmingham800
UKShoesBirmingham900
UKShoesBirmingham2000

<tbody>
</tbody>


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

Product
Highest Sales
Office
Shoes3700
Birmingham

<tbody>
</tbody>


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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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,215,518
Messages
6,125,292
Members
449,218
Latest member
Excel Master

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