- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Calculated column if date is within last 7 days using Calendar Dimension
I have two tables. One is a Calendar Dimension the other has values in it. They are linked by an ID, and I need to create a 'flag' to determine whether the value row is in the past 7 days, but I can't seem to get the relationship to work. I tried using USERELATIONSHIP and RELATED and RELATEDTABLE, but maybe I'm unable to get it to work.
Calendar Dimension:
Id | Date |
1 | 01/01/2021 |
2 | 02/01/2021 |
.. | .. |
4 | 20/01/2021 |
5 | 21/01/2021 |
Values table:
Value | DateID | InPast7Days |
500 | 1 | 0 |
-400 | 2 | 0 |
900 | 5 | 1 |
What i want is to use the relationship, to add the column with the 0's if the date is not within the past 7 days, and 1 if it is within the past 7 days. Hope this makes sense, and that you can help 🙂
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@C-Jac , Create new column in values table
if(related([Date]) >= today()-7 && related([Date]) <= today(),1,0)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@C-Jac , make sure a relationship is correctly established between two tables by this means: Calendar[ID] (1:*) Values[DateID]; then you might want to try adding a calculated column in Values table,
InPast7Days =
VAR __dt = RELATED ( Calendar[Date] )
RETURN
( TODAY () - 7 <= __dt && __dt <= TODAY() ) + 0
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thank you .ıt works
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, this works! 😄

Helpful resources
Subject | Author | Posted | |
---|---|---|---|
02-27-2024 02:53 PM | |||
Anonymous
| 12-15-2019 05:44 PM | ||
Anonymous
| 01-11-2024 08:34 AM | ||
01-13-2024 10:52 PM | |||
05-21-2024 03:42 PM |