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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Siboska
Helper II
Helper II

Help for finding error in Dax Formula

Hi, 

I have the following Dax Formula which is not returning the expected Result:

Dev. -1 month Benefits On Track KPI =

VAR _PreviousMonthBenefitsOnTrackKPI = CALCULATE(SUM(Initiatives[Benefits on track]), Initiatives[Snapshot type] = "End of month",HistoricalDatesInitiatives[Month relative today] = -1)

RETURN
IF(AND( _PreviousMonthBenefitsOnTrackKPI <> 1 || _PreviousMonthBenefitsOnTrackKPI <> 2 || _PreviousMonthBenefitsOnTrackKPI <> 3,  [Current Benefits On Track KPI] = 1),1,
 
IF(AND( _PreviousMonthBenefitsOnTrackKPI <> 1 || _PreviousMonthBenefitsOnTrackKPI <> 2 || _PreviousMonthBenefitsOnTrackKPI <> 3,  [Current Benefits On Track KPI] = 2 || [Current Benefits On Track KPI] = 3), -1,

_PreviousMonthBenefitsOnTrackKPI -  [Current Benefits On Track KPI]))



The idea is I have 3 If statements. 
The first states that if _PreviousMonthBenefitsOnTrackKPI Is NOTIN (1,2,3) AND [Current Benefits On Track KPI] = 1 THEN RETURN1 ELSE 
IF _PreviousMonthBenefitsOnTrackKPI IS NOTIN (1,2,3) AND [Current Benefits On Track KPI] IS IN (1,2)  THEN RETURN -1
ELSE
_PreviousMonthBenefitsOnTrackKPI -  [Current Benefits On Track KPI]

The issue is that some of my projects Returns the second statement -1 which in reality should return the last statement. 
I think the problem is related to how i'm nesting my IF's, AND's and OR's but can't fint the problem. 

Hope someone can help 
1 ACCEPTED SOLUTION

Thx for the reply. 
Made a mistake in my explanation. It should be 2 or 3. 

Somehow when I changed my logic to Equal blank () or 0 it worked. Dunno if the <> operator was reading it the wrong way.

View solution in original post

2 REPLIES 2
johnt75
Super User
Super User

The 2nd if statement in your code is checking for current benefits being 2 or 3, but in your explanation you are checking for it to be 1 or 2. Try

Dev. -1 month Benefits On Track KPI =
VAR _PreviousMonthBenefitsOnTrackKPI =
    CALCULATE (
        SUM ( Initiatives[Benefits on track] ),
        Initiatives[Snapshot type] = "End of month",
        HistoricalDatesInitiatives[Month relative today] = -1
    )
VAR _CurrentBenefitsOnTrackKPI = [Current Benefits On Track KPI]
RETURN
    IF (
        NOT ( _PreviousMonthBenefitsOnTrackKPI IN { 1, 2, 3 } )
            && _CurrentBenefitsOnTrackKPI = 1,
        1,
        IF (
            NOT ( _PreviousMonthBenefitsOnTrackKPI IN { 1, 2, 3 } )
                && _CurrentBenefitsOnTrackKPI IN { 1, 2 },
            -1,
            _PreviousMonthBenefitsOnTrackKPI - _CurrentBenefitsOnTrackKPI
        )
    )

Thx for the reply. 
Made a mistake in my explanation. It should be 2 or 3. 

Somehow when I changed my logic to Equal blank () or 0 it worked. Dunno if the <> operator was reading it the wrong way.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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