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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
acg
Resolver I
Resolver I

List highest score for each provider from a range of tables.

 

 

I have a table with the provider and up to  5 different countries they deal with. THe risk scores have been displayed. I need to be able to say what is the highest risk score for each provider and year.

If there are counties with the same risk score, then the country that appears first is taken. 

IN SQL I solved this sort of thing like this:

, [Highest_Risk] AS(
SELECT *,
(SELECT MAX(v)
FROM (
VALUES (Country_change.[High_risk_country1]),
(Country_change.[High_risk_country2]),
(Country_change.[High_risk_country3]),
(Country_change.[High_risk_country4]),
(Country_change.[High_risk_country5])) AS value(v)

 

What do you do in Power BI?

ProviderCountry 1 risk scoreCountry 2 risk scoreCountry 3 risk scoreCountry 4 risk scoreCountry 5 risk scoreHighest risk score
1003213
2334525
3255323
4000101
5000000
       
       
1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @acg 

 

1) try to unpivot it in Power Query Editor. Write click the Provider Column and choose unpivot other columns. You make it like this:

FreemanZ_7-1677722494578.png

 

 

2) then plot a table visual with attribute column and a measure as simple as:

 

Measure = MAX(TableName[Value])

 

 

it worked like:

FreemanZ_0-1677722195895.png

 

 

View solution in original post

4 REPLIES 4
CNENFRNL
Community Champion
Community Champion

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTKAYmMgNgJiQ6VYnWgwyxiKTYDYFCwLkoGpM4ViY7iMCZJpBmCTQDRIxhRNBoJjYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Provider = _t, #"Country 1 risk score" = _t, #"Country 2 risk score" = _t, #"Country 3 risk score" = _t, #"Country 4 risk score" = _t, #"Country 5 risk score" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Provider", Int64.Type}, {"Country 1 risk score", Int64.Type}, {"Country 2 risk score", Int64.Type}, {"Country 3 risk score", Int64.Type}, {"Country 4 risk score", Int64.Type}, {"Country 5 risk score", Int64.Type}}),

    Max = Table.AddColumn(#"Changed Type", "Max", each List.Max(List.Skip(Record.ToList(_))))
in
    Max

CNENFRNL_0-1677732116417.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

smpa01
Super User
Super User

@acg  you can do this

highest = 
MAXX (
    {
        MAX ( tbl[Country 1 risk score] ),
        MAX ( tbl[Country 2 risk score] ),
        MAX ( tbl[Country 3 risk score] ),
        MAX ( tbl[Country 4 risk score] ),
        MAX ( tbl[Country 5 risk score] )
    },
    [Value]
)

 

smpa01_0-1677725069686.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

hi @smpa01 @acg 

 

that is quite an eye-opener, perfect if there are not too many country columns.

 

follow the logic, it is also good to add a calculated column like:

ColumnHighest = 
MAXX (
    {
        [Country 1 risk score],
        [Country 2 risk score],
        [Country 3 risk score],
        [Country 4 risk score],
        [Country 5 risk score]
    },
    [Value]
)

 

FreemanZ_0-1677728171571.png

 

FreemanZ
Super User
Super User

hi @acg 

 

1) try to unpivot it in Power Query Editor. Write click the Provider Column and choose unpivot other columns. You make it like this:

FreemanZ_7-1677722494578.png

 

 

2) then plot a table visual with attribute column and a measure as simple as:

 

Measure = MAX(TableName[Value])

 

 

it worked like:

FreemanZ_0-1677722195895.png

 

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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