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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
nrichards_au
Helper I
Helper I

Replace 0 with average of column

Hi All,

Looking for some guidance here.

 

Need to replace PY values of 0 with the average of PY where ENTITY, PC_GROUP & AC_GROUP are the same. 

 

Any one have any ideas on how it can be done in DAX or should I be creating an aggregate table and linking it prior to the load?

 

ENTITYPC_GROUPAC_GROUPPERIODPYCY
E1PC1G1P0501
E1PC1G1P0611
E1PC1G1P071.48489471
E1PC1G1P0811.21053
E1PC1G1P091.32330831

 

1 REPLY 1
mahoneypat
Microsoft Employee
Microsoft Employee

I think this DAX will do what you are looking for.  I named the table "PYData" and added a Calculated Column with this expression:

 

Adj PY = var currentPY =PYData[PY]
var currentENT = PYData[ENTITY]
var currentPC = PYData[PC_GROUP]
var currentAC = PYData[AC_GROUP]
var avgsameENT_PC_AC = CALCULATE(AVERAGE(PYData[PY]), All(PYData), PYData[ENTITY]=currentENT, PYData[PC_GROUP]=currentPC, PYData[AC_GROUP]=currentAC)
return if(currentPY=0, avgsameENT_PC_AC, currentPY)
 
If this works, please mark it as solution.  Please let me know if any questions or not what you needed.
Regards,
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


Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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