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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Introduce a dynamic rank function based on user selection of calendar periods

 

 

To Introduce a dynamic rank function based on user selection of calendar periods (one each for Current Period and Prior Period) and the ranking of a dynamic changing weighted average costs measure.

1)Current Period: For the user selected months (multiple selection enabled slicer) in the slicer the maximum of the selected month is the current period.

2)Prior period: For the user selected months (multiple selection enabled slicer) in the slicer the minimum of the selected month is the current period.

3)Weighted Average Cost:

For calculating Weighted average cost we have two measures in practice

Calculate_TOTAL_COST = sum(F_WRIN_SUPPLIER_CSA_COST[COST_PER_UOM])*if(SUM(F_WRIN_SUPPLIER_CSA_COST[UOM_QTY_SHIPPED])==0,1,SUM(F_WRIN_SUPPLIER_CSA_COST[UOM_QTY_SHIPPED]))

Calculate_WT_AVG_COST = (

VAR qty = SUM(_SUPPLIER_CSA_COST[UOM_QTY_SHIPPED])

VAR SummarizedTable =

    ADDCOLUMNS(

        SUMMARIZE(

            _SUPPLIER_CSA_COST,

            D_SUPPLIERS[SUPPLIER_NAME],D_WRIN[WRIN_DESCRIPTION],F_WRIN_SUPPLIER_CSA_COST[TIME_FRAME]

        ),

        "totalcost", [Calculate_TOTAL_COST],

        "qty", qty

    )

return

    sumx(

        SummarizedTable,

        [totalcost]/[qty]

    )

 

)

 

 

 SUPPLIER_CSA_COST Table have cost component details and the rest info we are getting from multiple dim tables.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2 REPLIES 2
Anonymous
Not applicable

Hi @Anonymous ,

 

I think your calculation is based on your data model. Please share a sample file with me and show me a screenshot with the result you want. This will make it easier for me to find the solution.

 

Best Regards,
Rico Zhou

 

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

Anonymous
Not applicable

Hi Rico,

Thanks for your response.

Please find the below sample data

F_WRIN_SUPPLIER_CSA_COST table:

idxCATEGORYSUPPLIER_IDWRIN_IDCOST_TYPECOMPONENTCOMPONENT_TYPEUOMCOST_PER_UOMUOM_QTY_SHIPPEDTIME_PERIODSUPPLIER_RANKTIME_FRAMETIME_TYPE 
47526BUNSUPPLIER_19182WRIN_00001621FOBUTILITIESCONVERSIONDZ$0.02540Actual12021-07-01Monthly 
47514BUNSUPPLIER_19182WRIN_00001621FOBUTILITIESCONVERSIONDZ$0.02540Actual12021-10-01Monthly 
47502BUNSUPPLIER_19182WRIN_00001621FOBUTILITIESCONVERSIONDZ$0.07310Actual12022-01-01Monthly 
47550BUNSUPPLIER_19182WRIN_00001621FOBUTILITIESCONVERSIONDZ$0.02542,11,59,120Actual12021-01-01Monthly 
47538BUNSUPPLIER_19182WRIN_00001621FOBUTILITIESCONVERSIONDZ$0.02542,25,21,456Actual12021-04-01Monthly 

 

Wrin_prefix table dim

idxWRIN_IDPREFIX_ID 
166WRIN_00001621PREFIX_00001 
    
    


Prefix table dim:

 

idxPREFIX_IDPREFIX_ALIASPREFIX 
0PREFIX_00001100001-REGULAR BUNS 

 

Supplier table Dim:

idxSUPPLIER_IDSUPPLIER_ALIASSUPPLIER_NAMESUPPLIER_PARENT_NAMESUPPLIER_ZIPCODESUPPLIER_CITYSUPPLIER_STATESUPPLIER_COUNTRYTIME_ZONEREGION
24SUPPLIER_191821918219182-Foods INC.FOODS, INC.27520CLAYTONAustinUNITED STATESEastern Standard Time (EST)EAST

 

 

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.