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
Baarathi88
Helper III
Helper III

Dynamic Top Value of column based on Measure

I'm trying to add 2 measure values in Line Chart, both measure values have to show sales. But Measure1 should show value of the Company which has done most sales over a period of time and Measure2 should show second best Company which has done the most sales.

 

This Company should vary dynamically based on selection and even the label of measures value in line chart should vary dynamically.

 

Data Used :

YearCompanySales
2019CompanyA200
2019CompanyB500
2019CompanyC300
2019CompanyD800
2019CompanyE900
2019CompanyF600
2020CompanyA120
2020CompanyB50
2020CompanyC30
2020CompanyD80
2020CompanyE90
2020CompanyF45

 

 

Expected Output : 

 

Baarathi88_0-1594695806839.png

 

13 REPLIES 13
V-pazhen-msft
Community Support
Community Support

@Baarathi88 
Sorry for misunderstanding, I now see that you want compare the some of the company sales. 

You would need a calculate column first: 

 

Sum By Company = CALCULATE(SUM('Table'[Sales]),ALLEXCEPT('Table','Table'[Company]))

 

Then create two measures: 

 

Measure 1 = CALCULATE(SUM('Table'[Sales]),FILTER('Table',[Sum By Company]=MAX('Table'[Sum By Company])))
Measure 2 = CALCULATE(SUM('Table'[Sales]),FILTER('Table',[Sum By Company] = CALCULATE(MAX([Sum By Company]),FILTER('Table',[Sum By Company]<MAX([Sum By Company])))))

 

20192020measures.jpg


Paul Zheng _ Community Support Team
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@V-pazhen-msft  could you please share the file. The expression throws an error for me

@Baarathi88 

You should create Sum By Company using Calculate column not a measure. 


https://qiuyunus-my.sharepoint.com/:u:/g/personal/paul_qiuyunus_onmicrosoft_com/ETRwiL12lwdGnHQQ7U3I...

 


Paul Zheng _ Community Support Team
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@V-pazhen-msft But it is throwing an error refer below image

 

 

Baarathi88_0-1597064055174.png

 

Thank You @V-pazhen-msft  🙂 you have saved my day (Y)

amitchandak
Super User
Super User

@Baarathi88 , try like


Rank =rankx(all(Table[company]),calculate(sum(table[sales])),,desc,dense)

measure 1 = sumx(filter(values(Table[company]),[Rank]=1),Sum(table[sales]))
measure 2 = sumx(filter(values(Table[company]),[Rank]=2),Sum(table[sales]))

 

For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale
https://community.powerbi.com/t5/Community-Blog/Dynamic-TopN-made-easy-with-What-If-Parameter/ba-p/3...

@amitchandak  Thank You, but the concern with below expression is

measure 1 = sumx(filter(values(Table[company]),[Rank]=1),Sum(table[sales]))

 

For Example : In 2019 CompanyA is Rank = 1 and In 2020 CompanyB is Rank 1. Both CompanyA and CompanyB are represented in same line in the line chart.

 

But ideally, I need Ranking based on summation of sales for entire time period which has been selected.

For example, If Company A sales for 2019 + Company A sales for 2020 is highest. Then measure 1 should values of Company A in 2019 and 2020 in the line chart

 

Do you have any suggestions for that?

@Baarathi88 

You need to use allseleted() when you want the measures to be dynamic based on the selection on the slicer. 

 

Rank = RANKX(ALLSELECTED('Table'),CALCULATE(SUM('table'[sales])),,DESC,Dense)

Measure 1 = CALCULATE(SUM('Table'[Sales]),FILTER(ALLSELECTED('Table'),[Rank]=1))
Measure 2 = CALCULATE(SUM('Table'[Sales]),FILTER(ALLSELECTED('Table'),[Rank]=2))

 

 dynamic rank slicer.JPGdyanmic rank slicer 2020.JPG

 

Paul Zheng _ Community Support Team
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@V-pazhen-msft  Thank you for your response. Let me explain the scenario once again.

 

Measure1 should represent CompanyE (the company with most sales for period of 2019 and 2020 put together) 

 

Measure2 Should represent CompanyD (the company with 2nd most sales for period of 2019 and 2020 put together)

 

Thus when I create a line chart, Measure1 should represent CompanyE in LineChart . As the per the data the values in line chart should be 900 in 2019 and 90 in 2020

 

@amitchandak 

 

 

@Baarathi88 

Please give it a try, the is the linechart for the measures:

line chart.JPG

If that's not what you want, please provide your expected line graph with picture.


Paul Zheng _ Community Support Team
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@V-pazhen-msft  @amitchandak 

 below line chart is the sample output required based on the data i have provided

Baarathi88_0-1594807070248.png

 

@Baarathi88

For 2020, did you mean 120 for measure1, 90 for measure2. (The max is 120, second high sales is 90).

In this case, you do not need the rank measure, two simple measures should do. 

 

Measure 1 = MAX('Table'[Sales])
Measure 2 = CALCULATE(MAX('Table'[Sales]),FILTER('Table',[Sales]<MAX([Sales])))

 

 max and second max.JPG


Paul Zheng _ Community Support Team
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@V-pazhen-msft I'm Sorry, Actually this is not the actual solution, In the image that has been shared by you the value 120 is coming in dark blue line, as per my scenario, it should come under light blue line.

 

Light blue line should have maximum value - maximum value for 2019 is 900 and maximum value for 2020 in 120

 

According to your logic it is taking summation and determining the maximum which is not the right approach.

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.