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
Anonymous
Not applicable

DAX table it's not working anymore

I have used a table created with DAX in the past to use it as a date filter, and it worked perfectly. Now i want to use it again but it's not working anymore. It comes out with a syntax error. 

 

MTD/QTD/YTD =
VAR TodayDate = TODAY()
VAR YearStart = CALCULATE(STARTOFYEAR(Query1[Fecha]), YEAR(Query1[Fecha]) = YEAR(TodayDate))
VAR QuarterStart = CALCULATE(STARTOFQUARTER(Query1[Fecha]), YEAR(Query1[Fecha]) = YEAR(TodayDate), QUARTER(Query1[Fecha]) = QUARTER(TodayDate))
VAR MonthStart = CALCULATE(STARTOFMONTH(Query1[Fecha]), YEAR(Query1[Fecha]) = YEAR(TodayDate), MONTH(TodayDate) = MONTH(TodayDate))
VAR Result =
UNION(
ADDCOLUMNS(
CALENDAR(YearStart, TodayDate),
"Selection", "YTD"
),
ADDCOLUMNS(
CALENDAR(QuarterStart, TodayDate),
"Selection", "QTD"
),
ADDCOLUMNS(
CALENDAR(MonthStart, TodayDate),
"Selection", "MTD"
)
)
RETURN
Result))

 

Please help me to figure this out

1 ACCEPTED SOLUTION

There was a typo in the MonthStart variable.  Please try this instead.  However, this will generate a table where many dates are duplicated which measn you won't be able to "mark as date table" and/or use Time Intelligence functions.  And it will require M:M relationships with your other tables.  I would encourage you to get this same functionality using Calculation Groups (one Calculation Item for each of MTD, QTD, and YTD).

 

MTD/QTD/YTD =
VAR TodayDate =
    TODAY ()
VAR YearStart =
    CALCULATE (
        STARTOFYEAR ( Query1[Fecha] ),
        YEAR ( Query1[Fecha] ) = YEAR ( TodayDate )
    )
VAR QuarterStart =
    CALCULATE (
        STARTOFQUARTER ( Query1[Fecha] ),
        YEAR ( Query1[Fecha] ) = YEAR ( TodayDate ),
        QUARTER ( Query1[Fecha] ) = QUARTER ( TodayDate )
    )
VAR MonthStart =
    CALCULATE (
        STARTOFMONTH ( Query1[Fecha] ),
        YEAR ( Query1[Fecha] ) = YEAR ( TodayDate ),
        MONTH ( Query1[Fecha] ) = MONTH ( TodayDate )
    )
VAR Result =
    UNION (
        ADDCOLUMNS ( CALENDAR ( YearStartTodayDate )"Selection""YTD" ),
        ADDCOLUMNS ( CALENDAR ( QuarterStartTodayDate )"Selection""QTD" ),
        ADDCOLUMNS ( CALENDAR ( MonthStartTodayDate )"Selection""MTD" )
    )
RETURN
    Result

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Now is showing other error 

The True/False expression does not specify a column. Each True/False expressions used as a table filter expression must refer to exactly one column.Captura de pantalla (56).png

There was a typo in the MonthStart variable.  Please try this instead.  However, this will generate a table where many dates are duplicated which measn you won't be able to "mark as date table" and/or use Time Intelligence functions.  And it will require M:M relationships with your other tables.  I would encourage you to get this same functionality using Calculation Groups (one Calculation Item for each of MTD, QTD, and YTD).

 

MTD/QTD/YTD =
VAR TodayDate =
    TODAY ()
VAR YearStart =
    CALCULATE (
        STARTOFYEAR ( Query1[Fecha] ),
        YEAR ( Query1[Fecha] ) = YEAR ( TodayDate )
    )
VAR QuarterStart =
    CALCULATE (
        STARTOFQUARTER ( Query1[Fecha] ),
        YEAR ( Query1[Fecha] ) = YEAR ( TodayDate ),
        QUARTER ( Query1[Fecha] ) = QUARTER ( TodayDate )
    )
VAR MonthStart =
    CALCULATE (
        STARTOFMONTH ( Query1[Fecha] ),
        YEAR ( Query1[Fecha] ) = YEAR ( TodayDate ),
        MONTH ( Query1[Fecha] ) = MONTH ( TodayDate )
    )
VAR Result =
    UNION (
        ADDCOLUMNS ( CALENDAR ( YearStartTodayDate )"Selection""YTD" ),
        ADDCOLUMNS ( CALENDAR ( QuarterStartTodayDate )"Selection""QTD" ),
        ADDCOLUMNS ( CALENDAR ( MonthStartTodayDate )"Selection""MTD" )
    )
RETURN
    Result

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


speedramps
Super User
Super User

Hi juank_maxxom

 

Please consider this solution and leave Kudos ..

 

Try remove the )) at the end  .... that will cause a syntax error

 

 

 

RETURN
Result))
 
 

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.