SqueakyBeak
SqueakyBeak

Reputation: 434

Trouble getting datediff to work on added columns in dax studio

We'll call our parent table imported from a csv: 'a_generic_list'. I added 2 different addcolumns, calculated date columns in "yyyy-mm-dd" format: day1 and day2.

Example for day2:

addcolumns(...
                     "day2",
                        FORMAT (
                            CALCULATE (
                                MAXX ( 'a_generic_list', [Day] ),
                                FILTER (
                                    'a_generic_list',
                                           'a_generic_list'[Column1] = [filter1]
                                        && 'a_generic_list'[Column2] = [filter2]
                                        && 'a_generic_list'[Column3] = [filter3]
                                        && 'a_generic_list'[Column4] = [filter4]
                                        && 'a_generic_list'[Column5] = [filter5]
                                )
                            ),
                            "yyyy-mm-dd"
                        )
                ), ...

This evaluates correctly, and the table has a bunch of nested added columns.

I'm trying to add another column to subtract the two dates (day1 and day2) to get a difference in the unit of days, but I'm getting weird errors.

day1 day2 diffdate(in days)
2022-01-01 2022-01-03 2
2022-05-05
2023-02-03 2023-02-07 4
2022-05-05
2024-01-05 2024-01-06 1

I have it in a nested 'addcolumns' function, which has worked just fine with other variable columns under the 'define' part of the query. I'm also using not(isblank()) as a way to stop the calculation if there are blanks in either of the 2 columns I'm trying to do diffdate on. Here's how the code looks:

DEFINE
    VAR index_table =
....
    .... addcolumns(
     "datediff_days",
                        CALCULATE (
                            IF (
                                (
                                    NOT ( ISBLANK ( [day1] ) )
                                        && NOT ( ISBLANK ( [day2] ) )
                                ),
                                DATEDIFF ( [day1], [day2], DAY ),
                                blank
                            )
                        )
                )

    ......

evaluate 
index_table

The query formats fine in DAX Studio, but I keep getting a weird error:

"the syntax for ')' is incorrect"

But Im completing all the parenthesis in the correct spots as far as I know, and this is following the pattern of other added columns in the same table that had zero issues. Without this added column, the table evaluates successfully. Any thoughts?

edit: It seems like I might need to provide row context but Im struggling to get that to work.

Upvotes: 0

Views: 88

Answers (1)

Sam Nseir
Sam Nseir

Reputation: 12111

In your IF(...), it should be BLANK() not blank.

Upvotes: 1

Related Questions