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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
MarcoW91
Frequent Visitor

Trying to create a DAX code in which I can only apply the formula on a filtered selection

Hi all,

 

I got the following dax code:

 

Future Forecast =
 
    SUMX(
    'FC UnderRev',
    'FC UnderRev'[COS URev_FC] +
    'FC UnderRev'[COS URev_FC] * [WirePercentage] +
    'FC UnderRev'[COS URev_FC] * [WireRodPercentage] +
    'FC UnderRev'[COS URev_FC] * [ProfilePercentage] +
    'FC UnderRev'[COS URev_FC] * [PowderPercentage]
)
 
I want to apply this code only on the selected items from a filter which filters on DIM_SPGHierarchy[SPG].
If the item is not selected in the filter I want to apply the following formula:
  SUMX(
    'FC UnderRev',
    'FC UnderRev'[COS URev_FC])
 
This column DIM_SPGHierarchy[SPG] is also present in the endresult table and therefor is causing an issue as it will filter out the items which I put in the filter. I cannot get it to work with disconnecting filters to apply both formula's in the two cases (filtered out and filtered in).
 
Can someone please assist?
 
2 REPLIES 2
Anonymous
Not applicable

Hi @MarcoW91,

You can add a variable to store the selection items, then you can add if statements in your expression to achieve parameterized calculations:

Future Forecast =
VAR selection =
    VALUES ( DIM_SPGHierarchy[SPG] )
RETURN
    SUMX (
        'FC UnderRev',
        'FC UnderRev'[COS URev_FC]
            * (
                1
                    + IF ( "WirePercentage" IN selection, [WirePercentage] )
                    + IF ( "WireRodPercentage" IN selection, [WireRodPercentage] )
                    + IF ( "ProfilePercentage" IN selection, [ProfilePercentage] )
                    + IF ( "PowderPercentage" IN selection, [PowderPercentage] )
            )
    )

Regards,

Xiaoxin Sheng

lbendlin
Super User
Super User

I want to apply this code only on the selected items from a filter 

There's a DAX function for that - FILTERS().  Also read about VALUES() and ISFILTERED().

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 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.