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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
sstalcup
Frequent Visitor

DAX seems to only apply SWITCH function to column subtotals

Hello all,

 

I am trying to model an income statement in Power BI.

 

At a high level, I have 3 tables that are of interest:

- Accounting Dimensions (basically a list of accounts)

Accounting_Dimension_ID 
Accounting_Dimension_1Accounting_Dimension_1_Name Account_GroupingPowerBI_Sort
1012
100Sales - ExternalSales1
1028
nullnullGross Profit3

- Divisions

Division_IDCompanyDivisionDivision_NameDivision_DescriptionDivision_GroupingPower_BI_Sort
7100100Division 100Division 100Division 1001
6100160Division 160Division 160Division 1602

- Ledger

Ledger_Line_IDAccounting_DateRecorded_AmountAccounting_Dimension_IDDivision_ID
619572024-01-01-100.2510126
624852024-01-0112.5610026

The model is as follows:

sstalcup_0-1710510405987.png

 

I'm trying to use a DAX function to make calculations that summarize certain accounts in different ways. In this example, I'm trying to calculate gross profit based on the Sales amount - COGS. The DAX expression is as follows:

Test GP = 
SWITCH (
    TRUE (),
    MAX('Accounting Dimensions'[PowerBI_Sort]) = 3,
        CALCULATE (
            [Ledger $ Amount],
            FILTER (
                ALL('Accounting Dimensions'),
                'Accounting Dimensions'[PowerBI_Sort] IN {1, 2}
            )
        ),
    [Ledger $ Amount]
)

 

This doesn't quite work as expected, the calulation works for the column subtotal in the matrix visual, but does not work with the appropriate column context. You can see an example here:

sstalcup_1-1710510625472.png

 

Looking for some help how I might ensure the DAX calculation works for each column. 

 

1 ACCEPTED SOLUTION

It's not in a star schema - you have bidirectional links between all tables. Eliminate them if you can, make them single direction from the dimension to the fact.

View solution in original post

4 REPLIES 4
lbendlin
Super User
Super User

Your problem is quite a bit deeper than that.  Power BI likes to have a proper data model with dimension tables controlling fact tables in a Star schema.  You don't have that yet.  Before trying to troubleshoot the DAX you will want to fix your data model.

Do you have suggestions about how I might improve the data model?

I'm confident that the model is already in a star schema with the ledger (fact) having many to one relationships with the accounting dimensions (dim) and divisions (dim). I've greatly simplified the model for this post, but I'm certainly open to suggestions.

It's not in a star schema - you have bidirectional links between all tables. Eliminate them if you can, make them single direction from the dimension to the fact.

All I had to do was change the filter direction and it worked! Really appreciate the suggestion. Thanks!

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Kudoed Authors