Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

DAX & Empty Cells

Hey, so i'm trying to develop a DAX expression for day by day sales report but i'm having some trouble. Basically, some of the rows are empty because of store error or delay and my goal is to develop an expression where if there are more than 3 empty cells within a row, dont read it. Can this be done in dax?

 

Any help is appreciated, thanks in advance!

  • Hi Anonymous ,

     

    Parry2k has provided a  nice solution. If you want to use dax,It's a little bit of a hassle if you have a lot of columns, You can try the following dax:

    Measure =
    
    VAR MaxBlank = 3
    
    RETURN
    
        IF (
    
            CALCULATE (
    
                COUNTBLANK ( [COLUMN1] ) + COUNTBLANK ( [COLUMN2] )
    
                    + COUNTBLANK ( [COLUMN3] )
    
            ) >= MaxBlank,
    
            1,
    
            0
    
        )

    Best Regards,

    Dedmon Dai

6 Replies

  • mahoneypat's avatar
    mahoneypat
    Microsoft Employee

    Yes.  Please provide sample data if you want a detailed response with an expression.  But basically, you can make a variable as part of the expression to get the date of the last non-empty value, and find the difference from the current date (for example).  If >=3, return blank, if <  3, do your calculation.

     

    If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

    Regards,

    Pat

  • Anonymous how many columns you have? It is possible to check all the columns value and if 3 or more have blank values, flag it out but I'm thinking to a more sleek solution rather than writing simple and long DAX method, and that's the reason it will be good to know how many # of columns we are dealing with?

    • parry2k's avatar
      parry2k
      Super User

      Anonymous see attached, look at BlankExample table and fnCheckBlank function. Basically this fnCheckBlank function has 2nd parameter that you can pass on how many blank columns you want to check, 2 or 3 or 4 and you have a column with value Yes/No, Yes means # of blanks found in the row and now from here everything should be straight forward.

       

      it is a dynamic solution and can be applied to any number of columns in a table and can check any number of blank columns.

       

      PS - there are other tables in the attached pbix file, just ignore those.

       

      I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

       

       

  • Anonymous ,

    if this empty you can use blank to check. if it has space you need to use trim

    isblank([column]) is true when there is no data

    coalesce([column],"1")

    • parry2k's avatar
      parry2k
      Super User

      amitchandak not sure how it is going to help, it is not about checking if a column is blank, it is to check if there 3 or more columns are blank...maybe I misread the post but that's what I think Anonymous is looking for.

  • v-deddai1-msft's avatar
    v-deddai1-msft
    Community Support

    Hi Anonymous ,

     

    Parry2k has provided a  nice solution. If you want to use dax,It's a little bit of a hassle if you have a lot of columns, You can try the following dax:

    Measure =
    
    VAR MaxBlank = 3
    
    RETURN
    
        IF (
    
            CALCULATE (
    
                COUNTBLANK ( [COLUMN1] ) + COUNTBLANK ( [COLUMN2] )
    
                    + COUNTBLANK ( [COLUMN3] )
    
            ) >= MaxBlank,
    
            1,
    
            0
    
        )

    Best Regards,

    Dedmon Dai