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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

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
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.