Forum Discussion
Help with DAX in DATEADD
Hi,
i have the data in the following format
| date | mm - yyyy | loan id | network name | office name | amount |
| 8/9/2023 | 08 - 2023 | 1 | n1 | o1 | 200 |
| 8/9/2023 | 08 - 2023 | 3 | n1 | o1 | 100 |
| 8/8/2023 | 08 - 2023 | 2 | n2 | o2 | 500 |
MTD =
IF(ISNUMBER(SUM(Table[amount])),SUM(Table[amount]),0)
tot amt Last year =
CALCULATE(
[MTD],
DATEADD(
'Table'[MM-YYYY],
-1,
YEAR
)
)
Difference of year =
[MTD] - [tot amt Last year]
Percent.of year =
IF([tot amt Last year] = BLANK(),BLANK(),
DIVIDE([Difference of year],[tot amt Last year]))
This works perfectly fine until any filter is applied.
Once any of the filter is applied, the visual is collapsed and following errors is thrown.
I tried with sameperiodlastyear as well. But couldnt resolve this issue.
Please help
Thanks,
Dharani
5 Replies
- AnonymousNot applicable
No i didn't have a calendar table in the model
- AnonymousNot applicable
Make a date table with this code:
CalendarAuto()Go to "Model" view (on left hand side of desktop) and create a relationship between "Date" from your main table and date from the calendar table. Let me know if this fixes your measures.
- AnonymousNot applicable
Hi mate,
Do you have a Date/Calendar table in your data model? If so how is your relationship set up?
Thanks
- Ashish_Mathur
Super User
Hi,
I cannot understand your question. For the sample data that you have shared, explain the question and show the expected result. Be clear in your explanation.
- AnonymousNot applicable
Hi Anonymous ,
I suggest you to create a Calendar table with continuous date in it by CALENDAR()/CALENDARAUTO() function.
Then you can try SAMEPERIODLASTYEAR() function.
For reference: DATEADD "expects a contiguous selection when the date column is not unique, has gaps..."
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.