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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Help with Switch Measure and Subtotals

Hi,

I am trying to use dax to create an income statement and am having trouble getting the totals to work.  I want the measure to give me the line item value if the index (or summary index) does not indicate a subtotal.

 

Basically I am giving every line item an index and then each summary line item a second index. 

Here is what I am hoping to get with each line item displayed and then the total.   I need this to be in Excel and so some of the tricks that I have found only work in Power BI.  Can someone please help me with this measure?

 

Report NameABS PTD ACTUAL
Sales112,664,030
Sales Returns/Allowances10,017,049
Sales-Direct45,168,896
Sales-Discounts11,919,233
Sales-Freight1,118,574
Sales-Labor3,066,250
Sales-Service Local Buy-outs283
Sales-Service Mileage293,195
Sales-Service Misc Material79,618
Sales-Service Per Diem59,887
Sales-Service Special Services9,812
Sales-Subcontractor29,918
Total Sales627,130
Net Sales141,181,310

 

 

 

 

Here is what I am currently getting using the following measure. The tables are not joined.

 

=VAR MaxItem=max(MASTER_IS_TEMPLATE[Original Index])
Return( Switch(True(),
MaxItem=8,[Net Sales],
MaxItem=24,[Total Total COST Of Goods Sold],
CALCULATE( [ABS PTD ACTUAL],
FILTER( 'MASTER_IS_TEMPLATE', 'MASTER_IS_TEMPLATE'[Original Index] =MaxItem ) )))

Original IndexIS ItemSummary Index measure 3 
1Sales0 $         8,083,007.98
2Sales-Direct0 $         8,083,007.98
3Sales-Subcontractor0 $         8,083,007.98
4Sales - Labor0 $         8,083,007.98
5Sales - Freight0 $         8,083,007.98
6Total Sales0 $         8,083,007.98
7Sales Returns & Allowances0 $         8,083,007.98
8Net Sales1 $ (141,181,310.07)
4 REPLIES 4
Anonymous
Not applicable

Hi,

To give even more perspective. I am trying to just get a simple income statement in Excel, with blank rows where blank is indicated.  I need the subtotals (both $ and % to calculate accordingly).  As an example the first group sales, will total into "Net Sales".  It feels like there has to be a way to do an income statement like this in Excel.  Thanks

 

 

 

 

NameIndexGroup IndexBlank
Sales11 
Sales-Direct21 
Sales-Subcontractor31 
Sales - Labor41 
Sales - Freight51 
Total Sales61 
Sales Returns & Allowances71 
Net Sales 8  
 9 blank9
Cost of Goods Sold102 
Cos-Direct113 
Cos-Subcontractor122 
Cost of Goods Sold - Labor132 
Cos-Freight142 
Sales COGS152 
Sales Contribution162 
% Sales17  
 18 blank18
Loss/(Gain) on Inventory193 
Vendor Rebates203 
Early Pay Discounts214 
Freight Variance223 
Transfer Freight233 
Total Cost of Goods Sold24  
 25 blank25
Gross Profit26  
Gross Profit %27  
Anonymous
Not applicable

Hi @Anonymous ,

 

Depending on your description, you want to return specific measures [Net Sales] and [Total Total COST Of Goods Sold] when the original index is 8 or 24 (I can only consider them as measures for the time being, since there is no other information about them), and the other original index return the corresponding row of [ABS PTD ACTUA].

 

If my understanding is correct, I suggest you compare the ReportName and IS Item in CALCULATE to get the corresponding row of [ABS PTD ACTUA].

Measure3 = VAR MaxItem=max('Table (2)'[Original Index])//Table2 is a table with Original Index column
Return
Switch(TRUE(),
MaxItem=8,[Net Sales]
MaxItem=24,[Total Total COST Of Goods Sold],
CALCULATE(SUM('Table'[ABS PTD ACTUAL]),
FILTER( 'Table', 'Table'[Report Name] =MAX('Table (2)'[IS Item]) ) ))

vmengmlimsft_0-1735625947192.png

Note: In my test, I'm replacing them with numbers because of the lack of information about [Net Sales] and [Total Total COST Of Goods Sold]. Please provide more details if I understand incorrectly.

 

 

Best regards,

Mengmeng Li

 

 

Anonymous
Not applicable

Thanks for this.  

Basically, I have a template with an Income Statement layout (including subtotals and blank rows)

8 would be the index number for Net Sales.   

Why does the measure not work when I switch the hard coded value to be a measure (Net Sales). 

Here is the actual measure where the individual line items work but now the subtotals don't calculate correctly.

=VAR MaxItem=max('MASTER_IS_TEMPLATE'[Original Index])

Return

Switch(TRUE(),

MaxItem=8,[Net Sales],

MaxItem=24,[Total Total COST Of Goods Sold],

CALCULATE(SUM('Summarized GL Data'[Total Activity]),

FILTER( 'Summarized GL Data', 'Summarized GL Data'[Report Name] =MAX('MASTER_IS_TEMPLATE'[IS Item]) ) ))

 

Anonymous
Not applicable

Hi @Anonymous ,

 

What is the DAX of your measure? The problem might be caused by the row context in the measure. It would be better to provide a link to the pbix file, which could help us with this issue.

 

Best regards,

Mengmeng Li

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors