+ Reply to Thread
Results 1 to 12 of 12

DAX measure using 'if' returns zero rather than false = " "

  1. #1
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    610

    DAX measure using 'if' returns zero rather than false = " "

    Hi all,

    I have a measure which uses and if function, but even though I've eded with fasle = " " when dropped into a pivot table
    I get 0's where the for in this case "b" and "c".

    Does anyone know why and also I've been trying to write it as a measure within a measure to save typing a everything twice

    so I could just use If( measure = true , measure = false , " " )

    I've attached workbook and notepad with examples of what I've trued so far.

    Richard.
    Attached Files Attached Files

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: DAX measure using 'if' returns zero rather than false = " "

    Quote Originally Posted by Dicken View Post
    so I could just use If( measure = true , measure = false , " " )
    What does that actually mean? Your measure returns a number, not True/False.
    Rory

  3. #3
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    610

    Re: DAX measure using 'if' returns zero rather than false = " "

    Sorry I though that would make things clearer, obviously not, if the measure is true then use the measure if it is not true return a blank.
    Just wondered how to avoid having to type the entire formula out twice which is what I've done in the attachment.

    Richard.

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: DAX measure using 'if' returns zero rather than false = " "

    Again, your measure does not return True or False, so what do you mean by that?

  5. #5
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    610

    Re: DAX measure using 'if' returns zero rather than false = " "

    Sorry , I'm confusing myself, essentially I have a measure which runs ;

    < if ( VAR mdate = MAX(Table1[Date]) RETURN CALCULATE(SUM(Table1[Units]),

    KEEPFILTERS(Table1[Product]="a"),

    FILTER(ALL(Table1[Date]),Table1[Date]<=mdate && Table1[Date]> EOMONTH(mdate,-1)) ),

    (then) VAR mdate = MAX(Table1[Date]) RETURN CALCULATE(SUM(Table1[Units]),

    KEEPFILTERS(Table1[Product]="a"),

    FILTER(ALL(Table1[Date]),Table1[Date]<=mdate && Table1[Date]> EOMONTH(mdate,-1)) )

    (otherwise) , " " ))

    This return what I wanted all in a pivot table all the product column remains but I only have running total for "a"
    and I wondered if it would be possible somehow to declare it once as a Variable and then use something like ;



    If ( Variable , Variable , " " )

    Rory gave me the idea in reply earlier question.

    Richard.

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: DAX measure using 'if' returns zero rather than false = " "

    You keep repeating IF(measure, measure, "") when measure doesn't return true or false. Do you mean you want to return "" when the sum is 0, or something else?

    Rory gave me the idea in reply earlier question.
    I know - I am he.

  7. #7
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    610

    Re: DAX measure using 'if' returns zero rather than false = " "

    Actually I've checked and it was Bo_Ry he suggested making a measure using a variable;

    So ; measure:= VAR V-name = sum(Table [column ] ) RETURN if ( V-name , V-name, " " )

    and I'd like to do the same that is create a variable for the above rather than typing everything twice, but as it also contains a variable I'm having difficulties. Oh, and yes I'd also like to find out why it reuturns zero's rather than just a blank, ever when " " is used at the end?

    Richard.

  8. #8
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: DAX measure using 'if' returns zero rather than false = " "

    Hi,

    It might be clearer if you explained what your expected results were, and why.

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  9. #9
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    610

    Re: DAX measure using 'if' returns zero rather than false = " "

    The expected result is the same as the result in the attached workbook, I just don't want to have to type everything twice,
    so I thought if it is possible to declare it as a variable and then use that . but as the formua contains a variable in itself I don't seem to be able to get it right.
    Essentially you suggested I use the following for a similar situation ;

    < measure VAR name = SUM( Table[Column] ) RETURN
    IF ( name, name, " " ) >


    Also if you have an explanation as to why when dropped in a pivot table it return zero's rather then just a blank I'd be interested to know.

    Richard.

  10. #10
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: DAX measure using 'if' returns zero rather than false = " "

    Like the other repliers, I'm still confused as to under what conditions the result of the measure should be returned. IF(measure, doesn't really mean much - if the result of the measure is equal to what?

    Regards

  11. #11
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    610

    Re: DAX measure using 'if' returns zero rather than false = " "

    Hi,
    I know this goes back some time, but I managed to get what I wanted, and have attached a small work book with two measures,
    one with IF and one without, showing what I meant, essentially applying an internal filter but still keep the entire pivot table when it's dropped in.

    Richard.
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    610

    Re: DAX measure using 'if' returns zero rather than false = " "

    Hello,
    I know I raised this some time ago, but have only just discovered that rather than
    declaring the formula as a variable and then using

    = if ( VAR, VAR, "" )

    , to keep rows without data, you can just
    go to options, display, show items with no data, there's also a similar option in power bi, on the Column and Row drop down menus.
    But you probably knew that already. 😉
    RD

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Returns "FALSE" instead of "TRUE"
    By neutral5 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-05-2019, 12:06 AM
  2. Replies: 4
    Last Post: 10-30-2017, 07:07 AM
  3. [SOLVED] Nested HLOOKUP returns "FALSE" in cell where result should be "0.00"
    By gammccubbin in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-09-2016, 09:49 AM
  4. [SOLVED] IF Statement Evaluates as "TRUE" but Returns "FALSE" Value (Excel 2007)
    By Simcik in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-11-2014, 12:43 PM
  5. [SOLVED] if formula returns ":false" instead of "0"
    By pja_14 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-20-2013, 04:09 AM
  6. Using "IF" with date returns an improper "FALSE"
    By scaffdog845 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-23-2008, 10:31 AM
  7. [SOLVED] First part of "IF" function returns false even if true. ??
    By Bill R in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 04:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1