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
kompalli
Helper I
Helper I

Ranking based line chart

Hi all,

Actually I am trying to create a line chart by using ranking.

Sample scenerio:

If I have  company A with many products  and other companies(like B,C, D considered as others).I have ranked based on sales for 'A' and others individually and took Top 1 rank of 'A' company and top 1 rank of others same way based on that I have considered top 5 ranks of 'A' and top 5 ranks of others individually. Now I want to combine all these to get a line chart that displays top 5 products of company 'A' based on ranks considered and top 5 products of others as a line chart. Any suggestion would be truly be appreciated and helpful.

Thanks in advance.

3 ACCEPTED SOLUTIONS

Hi @kompalli ,

Please refer to my pbix file to see if it helps you.

Create a column.

Column = var _1= RANKX(FILTER(ALL('Table'),'Table'[A and others]=EARLIER('Table'[A and others])),'Table'[Sales],,DESC,Dense)
return
IF(_1<=5,_1,BLANK())

Then filter the line chart: Column is not blank.

vpollymsft_1-1669101732350.png

 

If I have misunderstood your meaning, please provide your pbix file without privacy information and desired output with more details.

 

Best Regards

Community Support Team _ Polly

 

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

Hi @v-rongtiep-msft ,

Thanks for your response. Below are the measures for your reference that I have used to rank company "A" and "others" based on product, company and sales measures. It was working fine but when used as measure, the same logic I couldn't apply it to a calculated column. 

 

Rank by A Sales = if (SELECTEDVALUE (Table name [Company]) ="A”, RANKX (

SUMMARIZE (ALL (Table name), Table name [Product], Table name [Company]), [Sales measure], CALCULATE ([Sales measure], Table name [company] = "A"), DESC, Dense))

 

Rank by others Sales = if (SELECTEDVALUE (Table name [Company]) ="others”, RANKX (SUMMARIZE (ALL (Table name), Table name [Product], Table name [company), [Sales measure], CALCULATE ([Sales measure]Table name [company] = "others"), DESC, Dense))

 

These are the measures used to rank based on company “A” and “others” but based on these conditions a calculated column is required. I tried doing it but I couldn't get the desired ranking.

  • Below image is that shows the expected output in detail. 
  • There might be similar products repeating for a company over a period based on sales.

Detailed representation.png

  • Below is the sample data for your reference.
  • CompanyProductDateSalesA and others
    AA0101-Feb-2050A
    AA0201-Feb-2036A
    AA0301-Feb-2043A
    AA0401-Feb-2031A
    BB0101-Feb-2016others
    BB0201-Feb-2049others
    BB0301-Feb-2027others
    BB0401-Feb-2042others
    CC0101-Feb-2056others
    CC0201-Feb-2011others
    CC0301-Feb-2013others
    CC0401-Feb-2030others
    AA0101-Mar-2031A
    AA0201-Mar-2023A
    AA0301-Mar-2044A
    AA0401-Mar-2029A
    BB0101-Mar-2024others
    BB0201-Mar-2011others
    BB0301-Mar-2011others
    BB0401-Mar-2024others
    CC0101-Mar-2015others
    CC0201-Mar-2053others
    CC0301-Mar-2058others
    CC0401-Mar-2018others
    AA0101-Apr-2047A
    AA0201-Apr-2027A
    AA0301-Apr-2027A
    AA0401-Apr-2044A
    BB0101-Apr-2049others
    BB0201-Apr-2037others
    BB0301-Apr-2025others
    BB0401-Apr-2027others
    CC0101-Apr-2030others
    CC0201-Apr-2033others
    CC0301-Apr-2028others
    CC0401-Apr-2019others
    AA0101-May-2034A
    AA0201-May-2052A
    AA0301-May-2050A
    AA0401-May-2027A
    BB0101-May-2055others
    BB0201-May-2039others
    BB0301-May-2015others
    BB0401-May-2026others
    CC0101-May-2052others
    CC0201-May-2013others
    CC0301-May-2014others
    CC0401-May-2035

    others

View solution in original post

Hi @kompalli ,

I have created a simple smaple, please refer to it to see if it helps you.

ColumnA = VAR _1= RANKX(FILTER('Table','Table'[company]="A"&&'Table'[DATE]=EARLIER('Table'[DATE])),'Table'[sales],,DESC,Dense)
RETURN
IF(_1<=5&&'Table'[company]="A",_1,BLANK())
ColumnNOA = VAR _1= RANKX(FILTER('Table','Table'[company]<>"A"&&'Table'[DATE]=EARLIER('Table'[DATE])),'Table'[sales],,DESC,Dense)
RETURN
IF(_1<=5&&'Table'[company]<>"A",_1,BLANK())

vpollymsft_0-1669253530065.png

 

If it still does not help you, please peovide more details to explain: Company A, date 2020/2/1, the A02 's rankx is 2. There are 50(A01) ,43( A03) ,48(A06) ,40(A07)  bigger than it.

 

It seems other company  rankx by date. Why 42(B04) is 1?

 

Best Regards

Community Support Team _ Polly

 

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

10 REPLIES 10
v-rongtiep-msft
Community Support
Community Support

Hi @kompalli ,

I have created a simple sample, please reer to it to see if ithelps you.

Create a column.

RANKX = VAR _1= RANKX(FILTER('Table','Table'[company ]=EARLIER('Table'[company ])),'Table'[sales],,DESC,Skip)
RETURN
IF(_1<=5,_1,BLANK())

vpollymsft_0-1668749441352.png

If I have misunderstood your meaning, please provide your pbix file without privacy information and desired output with more details.

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-rongtiep-msft ,

Thankyou for responding with a sample file. I tried to share the .pbix file for clear understanding of requirement but I am unable to share it.

Hi @kompalli ,

Please refer to .

How to provide sample data in the Power BI Forum - Microsoft Power BI Community

 

How to Get Your Question Answered Quickly 

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-rongtiep-msft 

Below is the sample data  and I want to create calculated column based ranking as shown in the sample table "RANK" column. The Ranking should be done seperately based on the company A and others . 

 

Thankyou in advance

CompanyproductSalesA and othersDateRankYYYY MMM
AA0115A01-Jan-20102020 Jan
AA0216A01-Jan-2092020 Jan
AA0317A01-Jan-2082020 Jan
AA0418A01-Feb-2072020 Feb
AA0519A01-Feb-2062020 Feb
AA0620A01-Feb-2052020 Feb
AA0721A01-Mar-2042020 Mar
AA0822A01-Mar-2032020 Mar
AA0923A01-Mar-2022020 Mar
AA1024A01-Apr-2012020 Apr
BB0130others01-Apr-2092020 Apr
BB0229others01-Apr-20102020 Apr
BB0328others01-May-20112020 May
BB0427others01-May-20122020 May
BB0526others01-May-20132020 May
BB0625others01-Jun-20142020 Jun
BB0724others01-Jun-20152020 Jun
BB0823others01-Jun-20162020 Jun
BB0922others01-Jul-20172020 Jul
BB1021others01-Jul-20182020 Jul
CC0150others01-Aug-2012020 Aug
CC0249others01-Aug-2022020 Aug
CC0348others01-Aug-2032020 Aug
CC0447others01-Sep-2042020 Sep
CC0546others01-Sep-2052020 Sep
CC0649others01-Oct-2022020 Oct
CC0748others01-Nov-2032020 Nov
CC0843others01-Nov-2062020 Nov
CC0942others01-Dec-2072020 Dec
CC1041others01-Jan-2182020 Dec

Hi @kompalli ,

Please refer to my pbix file to see if it helps you.

Create a column.

Column = var _1= RANKX(FILTER(ALL('Table'),'Table'[A and others]=EARLIER('Table'[A and others])),'Table'[Sales],,DESC,Dense)
return
IF(_1<=5,_1,BLANK())

Then filter the line chart: Column is not blank.

vpollymsft_1-1669101732350.png

 

If I have misunderstood your meaning, please provide your pbix file without privacy information and desired output with more details.

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Hi @v-rongtiep-msft Thanks for the quick response. It worked but even product column should be part of ranking. So the ranking is done based on company,product column as well as sales. These three conditions into one dax to create calculated ranking column. Could please suggest an alternative where a sales measure can be added to the calculated ranking column.

Hi @kompalli ,

"So the ranking is done based on company,product column as well as sales." How to rank based on different product column? What is the result like? "an alternative where a sales measure can be added to the calculated ranking column." How the measure like ? Could you please provide more details like the Message 6? Please list all the outputs you want.

vpollymsft_0-1669165392413.png

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-rongtiep-msft ,

Thanks for your response. Below are the measures for your reference that I have used to rank company "A" and "others" based on product, company and sales measures. It was working fine but when used as measure, the same logic I couldn't apply it to a calculated column. 

 

Rank by A Sales = if (SELECTEDVALUE (Table name [Company]) ="A”, RANKX (

SUMMARIZE (ALL (Table name), Table name [Product], Table name [Company]), [Sales measure], CALCULATE ([Sales measure], Table name [company] = "A"), DESC, Dense))

 

Rank by others Sales = if (SELECTEDVALUE (Table name [Company]) ="others”, RANKX (SUMMARIZE (ALL (Table name), Table name [Product], Table name [company), [Sales measure], CALCULATE ([Sales measure]Table name [company] = "others"), DESC, Dense))

 

These are the measures used to rank based on company “A” and “others” but based on these conditions a calculated column is required. I tried doing it but I couldn't get the desired ranking.

  • Below image is that shows the expected output in detail. 
  • There might be similar products repeating for a company over a period based on sales.

Detailed representation.png

  • Below is the sample data for your reference.
  • CompanyProductDateSalesA and others
    AA0101-Feb-2050A
    AA0201-Feb-2036A
    AA0301-Feb-2043A
    AA0401-Feb-2031A
    BB0101-Feb-2016others
    BB0201-Feb-2049others
    BB0301-Feb-2027others
    BB0401-Feb-2042others
    CC0101-Feb-2056others
    CC0201-Feb-2011others
    CC0301-Feb-2013others
    CC0401-Feb-2030others
    AA0101-Mar-2031A
    AA0201-Mar-2023A
    AA0301-Mar-2044A
    AA0401-Mar-2029A
    BB0101-Mar-2024others
    BB0201-Mar-2011others
    BB0301-Mar-2011others
    BB0401-Mar-2024others
    CC0101-Mar-2015others
    CC0201-Mar-2053others
    CC0301-Mar-2058others
    CC0401-Mar-2018others
    AA0101-Apr-2047A
    AA0201-Apr-2027A
    AA0301-Apr-2027A
    AA0401-Apr-2044A
    BB0101-Apr-2049others
    BB0201-Apr-2037others
    BB0301-Apr-2025others
    BB0401-Apr-2027others
    CC0101-Apr-2030others
    CC0201-Apr-2033others
    CC0301-Apr-2028others
    CC0401-Apr-2019others
    AA0101-May-2034A
    AA0201-May-2052A
    AA0301-May-2050A
    AA0401-May-2027A
    BB0101-May-2055others
    BB0201-May-2039others
    BB0301-May-2015others
    BB0401-May-2026others
    CC0101-May-2052others
    CC0201-May-2013others
    CC0301-May-2014others
    CC0401-May-2035

    others

Hi @kompalli ,

I have created a simple smaple, please refer to it to see if it helps you.

ColumnA = VAR _1= RANKX(FILTER('Table','Table'[company]="A"&&'Table'[DATE]=EARLIER('Table'[DATE])),'Table'[sales],,DESC,Dense)
RETURN
IF(_1<=5&&'Table'[company]="A",_1,BLANK())
ColumnNOA = VAR _1= RANKX(FILTER('Table','Table'[company]<>"A"&&'Table'[DATE]=EARLIER('Table'[DATE])),'Table'[sales],,DESC,Dense)
RETURN
IF(_1<=5&&'Table'[company]<>"A",_1,BLANK())

vpollymsft_0-1669253530065.png

 

If it still does not help you, please peovide more details to explain: Company A, date 2020/2/1, the A02 's rankx is 2. There are 50(A01) ,43( A03) ,48(A06) ,40(A07)  bigger than it.

 

It seems other company  rankx by date. Why 42(B04) is 1?

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

daXtreme
Solution Sage
Solution Sage

The description is not clear at all. Please read this first: How to Get Your Question Answered Quickly - Microsoft Power BI Community

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.

Top Solution Authors