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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
bagabo
Frequent Visitor

Getting City with highest sum of hours per customer

Hi there!

As in the subject, i'm currently searching for a formula to get the city with the highest sum of hours per customer.
So in the example, the customer has a variety of hours in the citys "Hamburg", "Kiel", "Rostock" and "Ruhr". But i want to find the City with the maximum sum of hours and write that into a new column for every customer.

Screenshot 2021-09-08 112326.png

So in this example, if he hast the most hours in "Hamburg", in every of the rows in the new column should be "Hamburg".
I tried a lot of things, but either it didn't work as planned or i get confusing errors like "circular dependency".

Thanks in advance!

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @bagabo ;

You could try create columns as follows:

RANK = 
RANKX ( 'Table',
        CALCULATE (
            SUM ( [Total Time and Work] ),
            ALLEXCEPT ( 'Table', 'Table'[WC Employee], 'Table'[Niederlassung] )),,ASC,DENSE)
highest =
CALCULATE (
    MAX ( [Niederlassung] ),
    FILTER (
        ALLEXCEPT ( 'Table', 'Table'[WC Employee] ),
        [RANK]= CALCULATE ( MAX ( [RANK] ), ALLEXCEPT ( 'Table', 'Table'[WC Employee] ) )))

Another method is create a column or a measure.

Highest2 =
CALCULATE (
    MAX ( [Niederlassung] ),
    FILTER (ALLEXCEPT ( 'Table', 'Table'[WC Employee] ),
        CALCULATE (SUM ( [Total Time and Work] ),ALLEXCEPT ( 'Table', 'Table'[WC Employee], 'Table'[Niederlassung] ))
            = MAXX ( ALLEXCEPT ( 'Table', 'Table'[WC Employee] ),
                CALCULATE ( SUM ( [Total Time and Work] ),ALLEXCEPT ( 'Table', 'Table'[WC Employee], 'Table'[Niederlassung] ) ))))

The final output is shown below:

vyalanwumsft_0-1631500282259.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

Why do you want to create a calculated column formula for this?  Why not a measure?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-yalanwu-msft
Community Support
Community Support

Hi, @bagabo ;

You could try create columns as follows:

RANK = 
RANKX ( 'Table',
        CALCULATE (
            SUM ( [Total Time and Work] ),
            ALLEXCEPT ( 'Table', 'Table'[WC Employee], 'Table'[Niederlassung] )),,ASC,DENSE)
highest =
CALCULATE (
    MAX ( [Niederlassung] ),
    FILTER (
        ALLEXCEPT ( 'Table', 'Table'[WC Employee] ),
        [RANK]= CALCULATE ( MAX ( [RANK] ), ALLEXCEPT ( 'Table', 'Table'[WC Employee] ) )))

Another method is create a column or a measure.

Highest2 =
CALCULATE (
    MAX ( [Niederlassung] ),
    FILTER (ALLEXCEPT ( 'Table', 'Table'[WC Employee] ),
        CALCULATE (SUM ( [Total Time and Work] ),ALLEXCEPT ( 'Table', 'Table'[WC Employee], 'Table'[Niederlassung] ))
            = MAXX ( ALLEXCEPT ( 'Table', 'Table'[WC Employee] ),
                CALCULATE ( SUM ( [Total Time and Work] ),ALLEXCEPT ( 'Table', 'Table'[WC Employee], 'Table'[Niederlassung] ) ))))

The final output is shown below:

vyalanwumsft_0-1631500282259.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Awesome! This works just fine! Thank you very much

amitchandak
Super User
Super User

@bagabo , Assume you have a measure for total hours as hours,

you can create a rank like this and filter that =1 in visual level filter

 

rankx(filter(allselected(Table[City], Table[Customer]), [Customer] = max([customer])), [hours],,desc,dense)

Unfortunately, i cannot Filter this, cause I need also the data of the other cities, they should all summarize in the largest city.

I tried using 

LOOKUPVALUE(i3_Report[Niederlassung bereinigt];i3_Report[SUM p NL p CSE];MAX(i3_Report[SUM p NL p CSE]))

Where "SUM p NL p CSE" ist the sum of total hours per customer per city, but the problem is that it takes just the max value of this column, not the max value per customer. 




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.