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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
pandeion
New Member

Amend DAX to ignore exception

Hi All

I've enharited some dashboards and looking to simplify a measure now. This was originaly created in order to get certain values from a file if Period filter was 2021 P1-P3. Trying to simplify the measure and delete this exception now as it's not needed anymore. Everything else should be kept. Rather newbie here and struggling to follow the logic. Any ideas on how to approach this and delete the part i don't need anymore? TIA

pandeion_0-1713447949591.png

 

1 ACCEPTED SOLUTION

@pandeion 

This is based on my interpretation of your DAX code and your explanation or the requirement.

Answer as Number EUT YTD =
VAR latest_period =
    MAX ( 'D_SalesPeriod'[Period] )
VAR year_val =
    SELECTEDVALUE ( D_SalesPeriod[Cycle Year] )
VAR p1_p3 = "2021 P01-P03"
VAR not_total =
    ISINSCOPE ( 'EUT tab_dimentions'[Q_lc1] )
VAR result =
    IF (
        not_total,
        IF (
            year_val = 2021,
            CALCULATE ( SUM ( 'EUT P1-P3'[Value] ), 'D_SalesPeriod'[Period] = p1_p3 )
        )
            + CALCULATE (
                SUM ( 'F_Form Answer'[Answer as Number] ),
                D_SalesPeriod[Cycle Year] = year_val,
                'D_SalesPeriod'[Period] <= latest_period
            ),
        CALCULATE (
            SUM ( 'F_Form Answer'[Answer as Number] ),
            'EUT tab_dimentions'[Q_lc1] = "Conversion",
            D_SalesPeriod[Cycle Year] = year_val,
            'D_SalesPeriod'[Period] <= latest_period
        )
            - CALCULATE (
                SUM ( 'F_Form Answer'[Answer as Number] ),
                'EUT tab_dimentions'[Q_lc1] = "Losses",
                D_SalesPeriod[Cycle Year] = year_val,
                'D_SalesPeriod'[Period] <= latest_period
            )
            + IF (
                year_val = 2021,
                CALCULATE (
                    SUM ( 'EUT P1-P3'[Value] ),
                    'EUT tab_dimentions'[Q_lc1] = "Conversion",
                    'D_SalesPeriod'[Period] = p1_p3
                )
                    - CALCULATE (
                        SUM ( 'EUT P1-P3'[Value] ),
                        'EUT tab_dimentions'[Q_lc1] = "Losses",
                        ALL ( 'D_SalesPeriod'[Period] ),
                        'D_SalesPeriod'[Period] = p1_p3
                    )
            )
    )
RETURN
    RESULT + 0

View solution in original post

5 REPLIES 5
pandeion
New Member

Thanks! It has worked!

Anonymous
Not applicable

Hi @pandeion ,

 

Try to modify your formula like below:

Answer as Number EUT YTD =
VAR latest_period =
    MAX ( 'D_SalesPeriod'[Period] )
VAR year_val =
    SELECTEDVALUE ( D_SalesPeriod[Cycle Year] )
VAR not_total =
    ISINSCOPE ( 'EUT tab_dimentions'[Q_lc1] )
VAR result =
    IF (
        not_total,
        CALCULATE (
            SUM ( 'F_Form Answer'[Answer as Number] ),
            FILTER (
                ALL ( 'D_SalesPeriod' ),
                'D_SalesPeriod'[Cycle Year] = year_val
                    && 'D_SalesPeriod'[Period] <= latest_period
            )
        ),
        CALCULATE (
            SUM ( 'F_Form Answer'[Answer as Number] ),
            FILTER (
                ALL ( 'D_SalesPeriod' ),
                'D_SalesPeriod'[Cycle Year] = year_val
                    && 'D_SalesPeriod'[Period] <= latest_period
            ),
            'EUT tab_dimentions'[Q_lc1] = "Conversion"
        )
            - CALCULATE (
                SUM ( 'F_Form Answer'[Answer as Number] ),
                FILTER (
                    ALL ( 'D_SalesPeriod' ),
                    'D_SalesPeriod'[Cycle Year] = year_val
                        && 'D_SalesPeriod'[Period] <= latest_period
                ),
                'EUT tab_dimentions'[Q_lc1] = "Losses"
            )
    )
RETURN
    IF ( ISBLANK ( result ), 0, RESULT )

vkongfanfmsft_0-1713778116419.png

 

 

Best Regards,
Adamk Kong

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

tamerj1
Super User
Super User

Hi @pandeion 
Please copy and paste the measure code in a reply.

Hey tamerj1! Thanks for replying, code below.

 

Answer as Number EUT YTD =

VAR latest_period = MAX('D_SalesPeriod'[Period])
var year_val = SELECTEDVALUE(D_SalesPeriod[Cycle Year])
VAR p1_p3 = "2021 P01-P03"
VAR not_total  = ISINSCOPE('EUT tab_dimentions'[Q_lc1])
VAR result =
IF(not_total,
   // Check if special case "2021 P1-P3"
    IF(latest_period = p1_p3,
        // Case 2021 P1 - P3
        CALCULATE(Sum('EUT P1-P3'[Value])),
        //Case 2021 P4 >=
        if(year_val=2021,CALCULATE(Sum('EUT P1-P3'[Value]), All('D_SalesPeriod'[Period]), 'D_SalesPeriod'[Period]=p1_p3),0) +
        CALCULATE(SUM('F_Form Answer'[Answer as Number]), All('D_SalesPeriod'[Period]),D_SalesPeriod[Cycle Year]=year_val, 'D_SalesPeriod'[Period]<=latest_period)),
    IF(latest_period = p1_p3,
        // Case 2021 P1 - P3
         CALCULATE(SUM('EUT P1-P3'[Value]), 'EUT tab_dimentions'[Q_lc1]="Conversion") -
         CALCULATE(SUM('EUT P1-P3'[Value]), 'EUT tab_dimentions'[Q_lc1]="Losses"),
        //Case 2021 P4 >=
        CALCULATE(SUM('F_Form Answer'[Answer as Number]), 'EUT tab_dimentions'[Q_lc1]="Conversion", All('D_SalesPeriod'[Period]), D_SalesPeriod[Cycle Year]=year_val,'D_SalesPeriod'[Period]<=latest_period) +
        if(year_val=2021,CALCULATE(SUM('EUT P1-P3'[Value]), 'EUT tab_dimentions'[Q_lc1]="Conversion", All('D_SalesPeriod'[Period]), 'D_SalesPeriod'[Period]=p1_p3),0) -
        if(year_val=2021,CALCULATE(SUM('EUT P1-P3'[Value]), 'EUT tab_dimentions'[Q_lc1]="Losses", All('D_SalesPeriod'[Period]), 'D_SalesPeriod'[Period]=p1_p3),0) -
        CALCULATE(SUM('F_Form Answer'[Answer as Number]), 'EUT tab_dimentions'[Q_lc1]="Losses", All('D_SalesPeriod'[Period]),D_SalesPeriod[Cycle Year]=year_val,'D_SalesPeriod'[Period]<=latest_period))
)
RETURN
IF(ISBLANK(result), 0, RESULT)
 

@pandeion 

This is based on my interpretation of your DAX code and your explanation or the requirement.

Answer as Number EUT YTD =
VAR latest_period =
    MAX ( 'D_SalesPeriod'[Period] )
VAR year_val =
    SELECTEDVALUE ( D_SalesPeriod[Cycle Year] )
VAR p1_p3 = "2021 P01-P03"
VAR not_total =
    ISINSCOPE ( 'EUT tab_dimentions'[Q_lc1] )
VAR result =
    IF (
        not_total,
        IF (
            year_val = 2021,
            CALCULATE ( SUM ( 'EUT P1-P3'[Value] ), 'D_SalesPeriod'[Period] = p1_p3 )
        )
            + CALCULATE (
                SUM ( 'F_Form Answer'[Answer as Number] ),
                D_SalesPeriod[Cycle Year] = year_val,
                'D_SalesPeriod'[Period] <= latest_period
            ),
        CALCULATE (
            SUM ( 'F_Form Answer'[Answer as Number] ),
            'EUT tab_dimentions'[Q_lc1] = "Conversion",
            D_SalesPeriod[Cycle Year] = year_val,
            'D_SalesPeriod'[Period] <= latest_period
        )
            - CALCULATE (
                SUM ( 'F_Form Answer'[Answer as Number] ),
                'EUT tab_dimentions'[Q_lc1] = "Losses",
                D_SalesPeriod[Cycle Year] = year_val,
                'D_SalesPeriod'[Period] <= latest_period
            )
            + IF (
                year_val = 2021,
                CALCULATE (
                    SUM ( 'EUT P1-P3'[Value] ),
                    'EUT tab_dimentions'[Q_lc1] = "Conversion",
                    'D_SalesPeriod'[Period] = p1_p3
                )
                    - CALCULATE (
                        SUM ( 'EUT P1-P3'[Value] ),
                        'EUT tab_dimentions'[Q_lc1] = "Losses",
                        ALL ( 'D_SalesPeriod'[Period] ),
                        'D_SalesPeriod'[Period] = p1_p3
                    )
            )
    )
RETURN
    RESULT + 0

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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