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
mdaamirkhan
Post Prodigy
Post Prodigy

Star Rating

Hello Everyone,

 

I have created quick measure "Star Rating" based on sales value but I dont the Value for highest star rating. Sales value either be Million or Billion or less.

 

How I want to set MAX_RATED_VALUE dynamic based on sales? Can you please help me on this ?

 

Sales_LCD star rating =
VAR __MAX_NUMBER_OF_STARS = 5
VAR __MIN_RATED_VALUE = 0
VAR __MAX_RATED_VALUE = 1000000
VAR __BASE_VALUE = SUM('Pfizer Champix QTR'[Sales_LCD])
VAR __NORMALIZED_BASE_VALUE =
MIN(
MAX(
DIVIDE(
__BASE_VALUE - __MIN_RATED_VALUE,
__MAX_RATED_VALUE - __MIN_RATED_VALUE
),
0
),
1
)
VAR __STAR_RATING = ROUND(__NORMALIZED_BASE_VALUE * __MAX_NUMBER_OF_STARS, 0)
RETURN
IF(
NOT ISBLANK(__BASE_VALUE),
REPT(UNICHAR(9733), __STAR_RATING)
& REPT(UNICHAR(9734), __MAX_NUMBER_OF_STARS - __STAR_RATING)
)

 

 

 

 

1 ACCEPTED SOLUTION

Hey,

 

thanks a lot for sharing your data.

 

Here you find a very simplified solution and here is an approach using your data

 

There is a difficulty how to determine the max value for "SALES_LCD", it's easy to use this DAX statement

 

MAXX SALES_LCD = 
MAXX(ALLSELECTED(data),data[Sales_LCD])

This statement returns the max value from the data table in a row based context. I created a little, little report thas show that for panel "FRANCE OFF-TAKE" the values SALES_LCD and MAXX ... do not match:

 

 This mismatch is due that there are more than one row for this panel in current filter context.

 

Within the simplified solution you also find another approach, using SUMMARIZE to aggregate Sales_LCD based on certain group by columns. This appoach delivers the max value in the current filter context but needs one or more grouping columns, but these grouping columns may depend on the selection of the usere. If you design this measre for a "fixed" report, where you know what is used in rows or columns you can use SUMMARIZE.

 

Hope this helps



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

9 REPLIES 9
lovermann
Frequent Visitor

It'd be better to show the table you have and describe the table you want to have.

I have attached the screenshot for Star Rating with table and query. In screenshot there sales table and Star Rating. I have set the Var _Max_RATED_VALUE = 1000000 manually  but how I will replace this "1000000" by dynamically by sales in Var _Max_RATED_VALUE. supposed I dont know the sales value its in Million or Billion or less value?

 

any update ?

Hey,

 

you already calculate the value for the variable

VAR __BASE_VALUE = SUM('Pfizer Champix QTR'[Sales_LCD])

Now try something like this for the variable

 

VAR __MAX_RATED_VALUE = 
CALCULATE(
  MAXX('your table', 'your table'[column that contain the values])
)

 

Hope this helps



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

I have tried your below query and showing all 5 stars which is wrong. Not working 

Hey,

can you prepare some sample data and share a link for downloading the data.


Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

I have prepared the sample data and shared the link : https://drive.google.com/open?id=0BxreilNC4AvsMW9QaWFUSGFZYlk

Hey,

 

thanks a lot for sharing your data.

 

Here you find a very simplified solution and here is an approach using your data

 

There is a difficulty how to determine the max value for "SALES_LCD", it's easy to use this DAX statement

 

MAXX SALES_LCD = 
MAXX(ALLSELECTED(data),data[Sales_LCD])

This statement returns the max value from the data table in a row based context. I created a little, little report thas show that for panel "FRANCE OFF-TAKE" the values SALES_LCD and MAXX ... do not match:

 

 This mismatch is due that there are more than one row for this panel in current filter context.

 

Within the simplified solution you also find another approach, using SUMMARIZE to aggregate Sales_LCD based on certain group by columns. This appoach delivers the max value in the current filter context but needs one or more grouping columns, but these grouping columns may depend on the selection of the usere. If you design this measre for a "fixed" report, where you know what is used in rows or columns you can use SUMMARIZE.

 

Hope this helps



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Thanks you very much 

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.