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.
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.
Please help me to figure this out
Solved! Go to 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 ( YearStart, TodayDate ), "Selection", "YTD" ),
ADDCOLUMNS ( CALENDAR ( QuarterStart, TodayDate ), "Selection", "QTD" ),
ADDCOLUMNS ( CALENDAR ( MonthStart, TodayDate ), "Selection", "MTD" )
)
RETURN
Result
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
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.
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 ( YearStart, TodayDate ), "Selection", "YTD" ),
ADDCOLUMNS ( CALENDAR ( QuarterStart, TodayDate ), "Selection", "QTD" ),
ADDCOLUMNS ( CALENDAR ( MonthStart, TodayDate ), "Selection", "MTD" )
)
RETURN
Result
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Hi juank_maxxom
Please consider this solution and leave Kudos ..
Try remove the )) at the end .... that will cause a syntax error
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
113 | |
97 | |
80 | |
69 | |
59 |
User | Count |
---|---|
150 | |
119 | |
104 | |
87 | |
67 |