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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Gangsta
Frequent Visitor

Measure to rank city based on % Increase from previous year for each product category and type

I would be greatful if some one can help me create a Measure that will rank each 'City' for each 'Product' and Type, based on % increase achieved in 'Current Year' vs 'Previous Year'.

 

So based on the data in the table below, the Measure will allow me to rank Cities as:

 

Digital, Computers, 

1 New York (300%)

2 London (0 %)

3 Paris (-33%)

 

Digital, Laptops, 

1 London (33 %)

2 New York (-44%)

3 Paris (-83%)

 

Appliance Cooker, 

1 Paris (-14%)

2 London (-100%)

 

I have added the a '% increase Previous Year' column to the table below to show what the increase is, this column is not in my data, I only put it in for reference, should I create this column in the data sheet?

 

CityTypeProductPrevious YearCurrent Year%Increase Previous Year
LondonDigitalComputers120%
LondonDigitalComputers430%
LondonDigitalLaptops3433%
LondonApplianceFridge26200%
LondonApplianceCooker10-100%
ParisDigitalComputers32-33%
ParisDigitalLaptops61-83%
ParisApplianceCooker42-14%
ParisApplianceCooker34-14%
ParisApplianceHob52-60%
New YorkDigitalLaptops64-44%
New YorkDigitalLaptops31-44%
New YorkDigitalComputers14300%
New YorkApplianceHob0550%
New YorkApplianceHob4150%
New YorkApplianceCooker01#DIV/0!
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Gangsta 

 

Thanks for the reply from bhanu_gautam .

 

@Gangsta , the following testing is for your reference.

 

Create two measures as follow

%Increase Previous Year = 
VAR _sumP = CALCULATE(SUM('Table'[Previous Year]), ALLEXCEPT('Table', 'Table'[City], 'Table'[Type], 'Table'[Product]))
VAR _sumC = CALCULATE(SUM('Table'[Current Year]) ,ALLEXCEPT('Table', 'Table'[City], 'Table'[Type], 'Table'[Product]))
RETURN
DIVIDE(_sumC - _sumP, _sumP)

 

rank = IF(NOT(ISBLANK([%Increase Previous Year])), RANKX(ALLEXCEPT('Table', 'Table'[Type], 'Table'[Product]), [%Increase Previous Year], , DESC, Dense))

 

Output:

vxuxinyimsft_0-1725520931970.png

 

Best Regards,
Yulia Xu

 

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

4 REPLIES 4
Anonymous
Not applicable

Hi @Gangsta 

 

Thanks for the reply from bhanu_gautam .

 

@Gangsta , the following testing is for your reference.

 

Create two measures as follow

%Increase Previous Year = 
VAR _sumP = CALCULATE(SUM('Table'[Previous Year]), ALLEXCEPT('Table', 'Table'[City], 'Table'[Type], 'Table'[Product]))
VAR _sumC = CALCULATE(SUM('Table'[Current Year]) ,ALLEXCEPT('Table', 'Table'[City], 'Table'[Type], 'Table'[Product]))
RETURN
DIVIDE(_sumC - _sumP, _sumP)

 

rank = IF(NOT(ISBLANK([%Increase Previous Year])), RANKX(ALLEXCEPT('Table', 'Table'[Type], 'Table'[Product]), [%Increase Previous Year], , DESC, Dense))

 

Output:

vxuxinyimsft_0-1725520931970.png

 

Best Regards,
Yulia Xu

 

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

@bhanu_gautam @Anonymous sorry been so busy with deadliens, I had just used a temp method as awork around.

I canc onfirm now that the solution posted works as I required and have now added the measures which you kindly provided, they are coming up with the same results, so they are 100% working for me.

 

Thanks again.

bhanu_gautam
Super User
Super User

@Gangsta ,First, create a calculated column to compute the percentage increase.

% Increase =
DIVIDE(
    [Current Year] - [Previous Year],
    [Previous Year],
    0
)
 
Next, create a measure to rank the cities based on the % increase.
DAX
City Rank =
VAR CurrentProduct = SELECTEDVALUE('Table'[Product])
VAR CurrentType = SELECTEDVALUE('Table'[Type])
VAR CurrentCity = SELECTEDVALUE('Table'[City])
VAR CurrentIncrease = CALCULATE(
SUM('Table'[% Increase]),
FILTER(
'Table',
'Table'[Product] = CurrentProduct &&
'Table'[Type] = CurrentType &&
'Table'[City] = CurrentCity
)
)
RETURN
RANKX(
FILTER(
ALL('Table'),
'Table'[Product] = CurrentProduct &&
'Table'[Type] = CurrentType
),
CALCULATE(
SUM('Table'[% Increase])
),
,
DESC,
DENSE
)
 
Use a table or matrix visual in Power BI to display the 'City', 'Type', 'Product', '% Increase', and 'City Rank' columns.



Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Thanks @bhanu_gautam with the way we using the % Increase column in the City Rank measure, would that not be averaging the averages once the dataset scales up to inlcde more 'Products'?

Would it be appropriate to create a % Increase Measure to create the figure needed for each City, based on Type and Prodcuct and instead of a calculated column?   If this can work, would be grateful if you can suggest the DAX for this.


That is assuming the % Increase measure be used within the City Rank Measure?

 

Many thanks once again.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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