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
akhtar0507
Frequent Visitor

P&L Help

Hello,

 

I have finally got my report to ressemble an income statement and all my measures are working fine individually. However, when I am summing my cost of sales and cost of sales B, it is returning blank as I am assuming the total cost of sales does not have any rows in the current context. 
Here is my formula that I am trying since few days. Can you please help me out?

 

Income Statement Amount =

VAR _currentItem = SELECTEDVALUE('GL Segment'[GL Grouping])
RETURN
SWITCH(TRUE(),
_currentItem = "Sales", [GL Total Sales],
_currentItem = "Cost of Sales",[GL Cost of sales Only],
_currentItem = "Cost of Sales B", [GL Cost of sales B],
_currentItem = "Total Cost of Sales", [GL Cost of sales Only] +  [GL Cost of sales B]
)
However, individually my formula is working fine, but the problem arises when I am trying to display it in my matrix. The total is good but the measure Total Cost of Sales is returning blank.

InkedP&L_LI.jpg

1 ACCEPTED SOLUTION

Try:

_currentItem = "Total Cost of Sales", CALCULATE( [GL Cost of sales Only], ALL ( GL Segment )) +  CALCULATE ( [GL Cost of sales B], ALL ( GL Segment) ))
 




Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

6 REPLIES 6
PaulDBrown
Community Champion
Community Champion

what are the measures in the total calculation?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Hello PaulDBrown,

The total contains Coat of sales B and Cost of Sales Only.

Thank you for helping. 

Right, but can post the  code for each measure?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






GL Cost of sales Only =
VAR _glGrouping = CALCULATETABLE( 'GL Segment', 'GL Segment'[GL Grouping] = "Cost of Sales")
VAR _netGL = [Net GL]
return
CALCULATE([Net GL],_glGrouping)
 
GL Cost of sales B =
VAR _glGrouping = CALCULATETABLE('GL Segment', 'GL Segment'[GL Grouping] = "Cost of Sales B")
VAR _netGL = [Net GL]
return
CALCULATE([Net GL],_glGrouping)
 
and for [Net GL] = sum(Debit) - sum(Credit) from the GL table.

Try:

_currentItem = "Total Cost of Sales", CALCULATE( [GL Cost of sales Only], ALL ( GL Segment )) +  CALCULATE ( [GL Cost of sales B], ALL ( GL Segment) ))
 




Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Hello PaulDBrown,

 

Big thumps up for your input.

Works like a charm 😄

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.