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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
hrnsyr
Frequent Visitor

Dax Query help

SUMX('Table (2)',
             IF(AND(NOT(ISBLANK([Current Year Value])),NOT(ISBLANK([Previous Year Value]))),0,
                    SWITCH(
                            TRUE(),
                                ISBLANK([Current Year Value]),[Previous Year Value],
                                ISBLANK([Previous Year Value]),[Current Year Value],
                                0
                            )
                )
            )
Above if statement doesn't return 0. It summing Currentyearvalue+ previousyearvalue and retrun but it supposed to return 0 according to logic. Is there any idea to fix?
9 REPLIES 9
hrnsyr
Frequent Visitor

It is a measure. Currentyear and Previousyear are measure as well. I am checking if those measures are not blank in the table I want to obtain 0 as a value and then not adding in the total value. I will attach the screenshot

hrnsyr_0-1679005005557.png

 

@hrnsyr Why not just +0 to the RETURN value for your measures?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler If I understood you correctly I modified if condtion with +0 but it is not working. It seems to me not applying If condition for some reason

@hrnsyr I was referring to +0 on your base measures so that you don't have to check for blank and return 0, they will just be 0 if they are blank because of the +0.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler The logic is that if currentyear and previousyear have value I need to skip or returen 0. They shouldn't be part of meaure in the table and then total will be calculated correctly, that's the reason I am implemnting if logic to assign 0 if they both have value. I hope it makes more sense now.

@hrnsyr Ahhh, OK so try something like this instead:

SUMX('Table (2)',
  SWITCH(TRUE(),
    [Current Year Value] > 0 && [Previous Year Value] > 0,0,
    [Current Year Value] > 0,[Previous Year Value],
    [Previous Year Value] > 0,[Current Year Value],
    0
  )

If that's not it, will need sample data as text and the formulas for your measures.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler  it didn't work. It returns each row 0 . I will copy the measures fromula  but I coudn't see any option to upload and file for sample data.

Current Year Value =

VAR curYear = YEAR(TODAY()) //Current Year
VAR nxtYear = YEAR(TODAY())+1 //Next Year
VAR fclYear =
IF(MONTH(TODAY()) < 2,
curYear,
nxtYear)
return
CALCULATE(SUM(table 2[Value]),FILTER((DATE_TABLE),VALUE(DATE_TABLE[Fiscal Year])=fclYear))


Previous Year value =
VAR curYear = YEAR(TODAY()) //Current Year
VAR nxtYear = YEAR(TODAY())+1 //Next Year
VAR fclYear =
IF(MONTH(TODAY()) < 2,
curYear,
nxtYear)
return
CALCULATE(SUM(table 2[Value]),FILTER((DATE_TABLE),VALUE(DATE_TABLE[Fiscal Year])=fclYear-1))

 

P/N =

SUMX(Table 2,
IF(AND(NOT(ISBLANK([Current Year Value])),NOT(ISBLANK([Previous Year Value]))),0,
SWITCH(
TRUE(),
ISBLANK([Current Year Value]),[Previous Year Value],
ISBLANK([Previous Year Value]),[Current Year Value]

)

)
)

hrnsyr
Frequent Visitor

Greg_Deckler
Super User
Super User

@hrnsyr Sample data would help along with measure formulas or is this a calculated column? Could be that your columns/measures aren't really blank?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors