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

How to have dynamic aggregation in PowerPivot?

Hello

 

I create a pivot in Excel and I put a field in the 'Values' area of the pivot. There I have to choose the type of aggregation, like sum, average etc.

 

Is it possible to choose different type of aggregation when a specific field contains a *string* and another type of aggregation for the other fields?

 

For example, my raw data is:

 

KPIDateValue
Sales01/01/2021142
Sales02/01/2021163
Sales03/01/2021184
Sales04/01/2021205
Sales05/01/2021226
Stock01/01/2021164
Stock02/01/2021172
Stock03/01/2021180
Stock04/01/2021188
Stock05/01/2021196

 

After I pivot it, it becomes:

 

Sum of ValueColumn Labels   
Row Labels01/01/202102/01/202103/01/202104/01/202105/01/2021
Sales142163184205226
Stock164172180188196
Grand Total306335364393422

 

How can I make it to sum the Sales and average the Stock?

 

Thanks!

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

 

Picture3.png

 

Expected result: =
SWITCH (
    SELECTEDVALUE ( Data[KPI] ),
    "Sales", SUM ( Data[Value] ),
    "Stock", AVERAGE ( Data[Value] ),
    BLANK ()
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
amitchandak
Super User
Super User

@Anonymous , If the model has been taken from power BI

Best is two measure

Sales sum= calculate(sum(Table[Value]), filter(Table, Table[KPI] = "Sales"))

 

Stock Avg= calculate(Average(Table[Value]), filter(Table, Table[KPI] = "Stock "))

 

 

or

If(Max(Table[KPI])= "Sales", Sum(Table[Value]) , Average(Table[Value]))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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.