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
johnny1
New Member

SWITCH function for P&L Statement

Like many others, I'm trying to build a P&L statement but have hit a wall. My goal is to include "calculated rows" in a matrix such as the following:

 

 

PLID            Category

0Gross Revenue
1Terms Discount
2Returns & Refunds
3Net Revenue
4 
5COGS
6 
7Product Profit
8Product Margin %
9 
10Freight Out
11Total COGS
12 
13Gross Profit
14Gross Margin %
15 
16Expenses
17Trade Spend
18Trade Events
19Retail Marketing
20Operating Expenses
21Total Expenses
22 
23Net Profit
24Net Margin

 

So far it appears the SWITCH function is the best workaround since Power BI lacks calculated rows. This is what I've tried using the column "PLID" as the anchor for the table I want to produce, but it fails miserably. Essentially, the values for all "SUM" functions pull in properly from a related table, but none of the "calculated measures" for margins or subtotals pull into the result. My guess is that there's an issue with the difference between some of the measures aggregating data from one source table and the rest of the calculated measures that are "measures of measures"? 

 

Thanks in advance for tips here... 

 

Switch Measure = 
    IF ( 
        HASONEVALUE('P&L Template'[PLID]),
            SWITCH( VALUES('P&L Template'[PLID]),
                0,[Sum Gross Revenue],
                1,[Sum Terms Discount],
                2,[Sum Returns & Refunds],
                3,[Net Revenue],
                4,"",         
                5,[Sum P&L COGS],
                6,"",
                7,[Product Profit],
                8,[Product Margin],
                9,"",
                10,[Sum Freight Out],
                11,[Total COGS],
                12,"",
                13,[Gross Profit],
                14,[Gross Margin],
                15,"",
                16,"",
                17,[Sum Trade Spend],
                18,[Sum Trade Events],
                19,[Sum Retail Marketing],
                20,[Sum Operating Expenses],
                21,[Total Expenses],
                22,"",
                23,[Net Profit],
                24,[Profit Margin %],
                BLANK(),"",
BLANK()            ))

 

 

2 REPLIES 2
v-yuta-msft
Community Support
Community Support

Hi johnny1,

 

"but none of the "calculated measures" for margins or subtotals pull into the result. My guess is that there's an issue with the difference between some of the measures aggregating data from one source table and the rest of the calculated measures that are "measures of measures"? "

 

<--- What's your expected result and could you please post the measures you are using and the "measures of measures" as you said? 

 

Regards,

Jimmy Tao

Seward12533
Solution Sage
Solution Sage

Can you provide more details about your model and measures?  What your doing should work, my guess its probably has to do with mulitple fact and lookup tables and the filter context not being applied the way you want. Ideally a sample PBIX with model and representative data vs actual data or at least pic of Model with relationsips and definitions of some of these measures you reference. and layout of matrix/visuals your trying to use.

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.