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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
v-shex-msft
Community Support
Community Support

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.