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
tim_g
Regular Visitor

How to get top value, then related value

I have a column of country codes that can occurs many times (us, ca, us, us, au, etc). I have another column with 2 words of text describing things about the country (nice + sunny, cold + rainy, etc):

1, us, warm + sunny 

2, ca, cold + icy

...

 

In another table (related by id) I have a measure that calculates the growth (current month count - prev month count) based on the submitted date:

1, 2nd Jan 2016

2, 4th Dec 2016

...

 

If I do a chart with: 

Axis:    CountryCode

Value:  Growth 

 

Then Order by growth desc, then select the top value ('ca', 120%), I can have a word cloud that shows the top word combination that people used to describe 'ca'. If I limit the word cloud to a single result, it shows the most common combination, 'cold + snowy'. 

 

I want to do the same, but using DAX. How to I extract this value 'cold + snowy' without having the user have to actually click the top value in the chart? I.e I want to show in the middle of the report, the most common words used in the fastest growing country.

 

Thanks!

1 ACCEPTED SOLUTION
v-ljerr-msft
Employee
Employee

Hi @tim_g,

 

According to your description, you should be able to use TOPN Function (DAX) and SUMMARIZE Function (DAX) to create a measure to get the top value in this scenario. The sample below is for your reference.

 

I assume you have the two tables like below.

Table1

t1.PNG

Table2

t2.PNG

 

1. Use the formula below to create a calculate table to get the "Id" with top Growth.

 

TopTable = 
TOPN (
    1,
    SUMMARIZE ( Table2, Table2[Id], "TotalGrowth", SUM ( Table2[Growth] ) ),
    [TotalGrowth]
)

toptable.PNG

 

 

2. Then you should be able to use the formula below to create a measure to get the top value and show it within a Card visual on the report.

 

TopValue = 
CALCULATE (
    FIRSTNONBLANK ( Table1[Description], 1 ),
    FILTER ( Table1, Table1[Id] = MAX ( 'TopTable'[Id] ) )
)

topvalue.PNG

 

 

Here is the sample pbix file for your reference.

 

Regards

View solution in original post

1 REPLY 1
v-ljerr-msft
Employee
Employee

Hi @tim_g,

 

According to your description, you should be able to use TOPN Function (DAX) and SUMMARIZE Function (DAX) to create a measure to get the top value in this scenario. The sample below is for your reference.

 

I assume you have the two tables like below.

Table1

t1.PNG

Table2

t2.PNG

 

1. Use the formula below to create a calculate table to get the "Id" with top Growth.

 

TopTable = 
TOPN (
    1,
    SUMMARIZE ( Table2, Table2[Id], "TotalGrowth", SUM ( Table2[Growth] ) ),
    [TotalGrowth]
)

toptable.PNG

 

 

2. Then you should be able to use the formula below to create a measure to get the top value and show it within a Card visual on the report.

 

TopValue = 
CALCULATE (
    FIRSTNONBLANK ( Table1[Description], 1 ),
    FILTER ( Table1, Table1[Id] = MAX ( 'TopTable'[Id] ) )
)

topvalue.PNG

 

 

Here is the sample pbix file for your reference.

 

Regards

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.