Forum Discussion

user5341567's avatar
user5341567
Helper I
1 year ago
Solved

Showing an average for % when using TopN

Hi all,

 

I've been having some trouble getting my average % to show correctly when using TopN. I've created measures that display the correct results based on what's selected in the TopN slicer, and my totals are summing correctly which is great, but I have a YOY% field that's not averaging based on the TopN. It's rather showing the average of all styles, instead of TopN.

 

As an example, for this field, I'd expect to see 54%, instead of 16%:

 

 

I've searched the posts on here, posts on other sites, but can't find anyone who is trying to display an average based on TopN.

 

Here's what I'm working with:

 

ShowStyleSales = ROWNUMBER(ALLSELECTED(dim_class_desc[product_name]), ORDERBY([Net Sales],DESC)) <= SELECTEDVALUE('TopN'[TopN])
 
Units LY - Styles = IF([ShowStyleSales],[Units LY])
 
This what I'm using directly in the table:
 
Units YOY - Styles = IF([Units LY - Styles] > 0, [Units] / [Units LY - Styles] - 1)

 

Has anyone run across this issue? If anyone has a more simple way to do this, I'd love to hear it. I basically need to display Net Sales & Units on a style-level, and LY & YOY for each when TopN is selected. The YOY is what's giving me trouble.

 

Many thanks.

  • user5341567 
    Instead of directly averaging the Units YOY - Styles, try recalculating YOY% based on the aggregated totals of Units and Units LY:

    Corrected_YOY_Styles =
    VAR Total_Units = SUMX(FILTER(dim_class_desc, [ShowStyleSales]), [Units])
    VAR Total_Units_LY = SUMX(FILTER(dim_class_desc, [ShowStyleSales]), [Units LY])

    RETURN
    IF(Total_Units_LY > 0, (Total_Units / Total_Units_LY) - 1)

    Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!

2 Replies

  • user5341567 
    Instead of directly averaging the Units YOY - Styles, try recalculating YOY% based on the aggregated totals of Units and Units LY:

    Corrected_YOY_Styles =
    VAR Total_Units = SUMX(FILTER(dim_class_desc, [ShowStyleSales]), [Units])
    VAR Total_Units_LY = SUMX(FILTER(dim_class_desc, [ShowStyleSales]), [Units LY])

    RETURN
    IF(Total_Units_LY > 0, (Total_Units / Total_Units_LY) - 1)

    Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!

    • user5341567's avatar
      user5341567
      Helper I

      Excellent, this worked perfectly. Thank you for your response!