cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills 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
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

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

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors