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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Clementw66666
Frequent Visitor

Calculate total costs with different components on unpivot table

Hello everyone,

 

I have a table as per below screenshot. The table is about the costs of three types of products (pizza, pasta and Cola Cola).

 

I want to have the total costs for all three products by month. However, for Pizza and Pasta, there are only the sub-components for the total costs (Production + Marketing + Branch Store), and for Coca Cola there is already total costs which do not need to do a sum.

 

In the end I want to show the total costs for Pizza and Pasta as well, then using the total costs to do some analysis; if possible I would also like to keep it's sub-components, so I can create some pie-chart to connect with other charts.

 

Do you know how this can be done on Power BI? 

 

Thank you very much in advance!

Clementw66666_0-1740998701511.png

 

 

 

1 ACCEPTED SOLUTION
bhanu_gautam
Super User
Super User

@Clementw66666 , You can use UNPIVOT in power query then

In Power BI, go to the "Modeling" tab and create a new calculated column using the following DAX formula:

 

Total Costs =
IF(
'Table'[Type] = "Total Costs",
'Table'[Value],
CALCULATE(
SUM('Table'[Value]),
FILTER(
'Table',
'Table'[Category] = EARLIER('Table'[Category]) &&
'Table'[Date] = EARLIER('Table'[Date])
)
)
)

 

 

Total Costs by Month: Use a line chart or bar chart to show the total costs for each product by month.
Sub-Components Breakdown: Use a pie chart to show the breakdown of sub-components for Pizza and Pasta.

 




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

Proud to be a Super User!




LinkedIn






View solution in original post

2 REPLIES 2
bhanu_gautam
Super User
Super User

@Clementw66666 , You can use UNPIVOT in power query then

In Power BI, go to the "Modeling" tab and create a new calculated column using the following DAX formula:

 

Total Costs =
IF(
'Table'[Type] = "Total Costs",
'Table'[Value],
CALCULATE(
SUM('Table'[Value]),
FILTER(
'Table',
'Table'[Category] = EARLIER('Table'[Category]) &&
'Table'[Date] = EARLIER('Table'[Date])
)
)
)

 

 

Total Costs by Month: Use a line chart or bar chart to show the total costs for each product by month.
Sub-Components Breakdown: Use a pie chart to show the breakdown of sub-components for Pizza and Pasta.

 




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

Proud to be a Super User!




LinkedIn






Thank you very much!! It works.

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors