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
George1973
Helper V
Helper V

Optimization of Product Ranking Measure

Dear Community,

I have the measure calculating product sales ranking adding to them ABCDX priorities like given below:

Rank for Sales on Products = 
VAR RunningTotal_Prod_Sales=CALCULATE([Total Sales],TOPN([TotProduct Ranking per Sales],ALLSELECTED(Tables_Products),[Total Sales]))
VAR GrandTotal_for_TotalSales=CALCULATE([Total Sales],ALLSELECTED(Tables_Products))
VAR RunnigTotal_ProdSales_Shares=DIVIDE(RunningTotal_Prod_Sales,GrandTotal_for_TotalSales,0)

Return
SWITCH(TRUE(),RunnigTotal_ProdSales_Shares<=0.8,"A",
RunnigTotal_ProdSales_Shares>0.8 && RunnigTotal_ProdSales_Shares<=0.95,"B",
RunnigTotal_ProdSales_Shares>0.95 && RunnigTotal_ProdSales_Shares<=0.99,"C",
RunnigTotal_ProdSales_Shares>0.99 && RunnigTotal_ProdSales_Shares<=1,"D","X")

 

The measure works corectly, however the speed is too low, due to high number of recordset -  apprx. 1 min!

Please suggest to way how to optimize the measure.

 

Thanks in advance,

 

 

1 ACCEPTED SOLUTION

Hi,
Thanks a lot for the provided solution. I think there is a little mistake here:

George1973_0-1626699511298.png

Is the first viriable there should be "RunningTotal_Prod_Sales" instead of "RunnigTotal_Prodsales_Share"..

 

If I'm mistaken sorry for that 🙂

The formula speed has been optimized indeed by 3 times, but as for the results (outcome) I have to check it once again, there seems to be some deviations

View solution in original post

3 REPLIES 3
mahoneypat
Employee
Employee

Please try it with these changes

 

Rank for Sales on Products =
VAR summary =
    ADDCOLUMNS ( ALLSELECTED ( Tables_Products )"cSales", [Total Sales] ) // use a single column if possible in ALLSELECTED like Tables_Products[ProductID]
VAR RunnigTotal_Prodsales_Share =
    SUMX (
        TOPN ( [TotProduct Ranking per Sales], summary, [cSales], DESC ),
        [cSales]
    )
VAR GrandTotal_for_TotalSales =
    SUMX ( summary, [cSales] )
VAR RunnigTotal_ProdSales_Shares =
    DIVIDE ( RunningTotal_Prod_Sales, GrandTotal_for_TotalSales0 )
RETURN
    SWITCH (
        TRUE (),
        RunnigTotal_ProdSales_Shares <= 0.8"A",
        RunnigTotal_ProdSales_Shares > 0.8
            && RunnigTotal_ProdSales_Shares <= 0.95"B",
        RunnigTotal_ProdSales_Shares > 0.95
            && RunnigTotal_ProdSales_Shares <= 0.99"C",
        RunnigTotal_ProdSales_Shares > 0.99
            && RunnigTotal_ProdSales_Shares <= 1"D",
        "X"
    )

 

Pat





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

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Hi,
Thanks a lot for the provided solution. I think there is a little mistake here:

George1973_0-1626699511298.png

Is the first viriable there should be "RunningTotal_Prod_Sales" instead of "RunnigTotal_Prodsales_Share"..

 

If I'm mistaken sorry for that 🙂

The formula speed has been optimized indeed by 3 times, but as for the results (outcome) I have to check it once again, there seems to be some deviations

Hi Again,

 

Yes, the formula works great! As communicated by 3 times faster!

 

Thanks a lot for your support!

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