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.
Hello -
I'm trying to make a table with values in a column called "Selection" for MTD, YTD, PYTD, PMTD, and WEEKLY. I'm using the concept for intelligent time slicers linked here: (https://youtu.be/AdLDYohLeJc). I'm currently hung up on trying to generate the "Weekly" Selection. I can generate the dates properly for WTD using:
However, the data I would like to filter on this specific request is trailing by 3 weeks. How would I obtain a list of dates using the calendar function for a week of dates that is 3 weeks back? Ex. if the date is 8/22/22, I would like the list of days for the week of 8/1/22-through 8/7/22.
I have the extended date table available with week offsets, but I can't figure out how to use dax to get the dates I would like to display.
Thanks!
Solved! Go to Solution.
Hi @Alex_LevelUp ,
According to your description, According to your DAX, I can see that you want to get the date three weeks before TODAY().Right?
(1)You can use the following DAX to replace the italicized part of your error :
VAR WeekStart =
CALCULATE(
TodayDate-WEEKDAY(TodayDate,3)
,FILTER(
DISTINCT('Dates'[Date]),
YEAR('Dates'[date])
=YEAR(TodayDate)
)
)
VAR _pre_three_week_start =
CALCULATE(
DATEADD('Dates'[Date], -21, DAY),
FILTER(
'Dates','Dates'[Date]=WeekStart
)
)
VAR _pre_three_week_end =
CALCULATE(
DATEADD('Dates'[Date], -15, DAY),
FILTER(
'Dates','Dates'[Date]=WeekStart
)
)
(2)And the [Result] is :
ADDCOLUMNS(
CALENDAR(_pre_three_week_start, _pre_three_week_end),
"Selection", "WeeklyTEST",
"Sort", 7
)
(3)The Result as follows:
If this method can’t meet your needs, can you provide your Date table for us so that we can help you better.
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Alex_LevelUp ,
According to your description, According to your DAX, I can see that you want to get the date three weeks before TODAY().Right?
(1)You can use the following DAX to replace the italicized part of your error :
VAR WeekStart =
CALCULATE(
TodayDate-WEEKDAY(TodayDate,3)
,FILTER(
DISTINCT('Dates'[Date]),
YEAR('Dates'[date])
=YEAR(TodayDate)
)
)
VAR _pre_three_week_start =
CALCULATE(
DATEADD('Dates'[Date], -21, DAY),
FILTER(
'Dates','Dates'[Date]=WeekStart
)
)
VAR _pre_three_week_end =
CALCULATE(
DATEADD('Dates'[Date], -15, DAY),
FILTER(
'Dates','Dates'[Date]=WeekStart
)
)
(2)And the [Result] is :
ADDCOLUMNS(
CALENDAR(_pre_three_week_start, _pre_three_week_end),
"Selection", "WeeklyTEST",
"Sort", 7
)
(3)The Result as follows:
If this method can’t meet your needs, can you provide your Date table for us so that we can help you better.
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Perfect! Thank you for your help!
Hi @Alex_LevelUp ,
According to your description, you want to display the date of the third week before by a certain date. Right?
Here are the steps you can follow:
(1)We can create a date table using CALENDAR() based on test table. The two tables do not need to be connected.
Date = CALENDAR(FIRSTDATE('test'[Date]),LASTDATE('test'[Date]))
(2)We put the ‘Date’[Date] in the slice and put the ‘test’[Date] in the Table or Matrix.
(3)Create Measure “isDisplay”:
isDisplay =
var _week_day= WEEKDAY(SELECTEDVALUE('Date '[Date]),3)
var _week_start= DATEADD( VALUES('Date '[Date]), -_week_day,DAY)
var _pre_three_week_start= DATEADD(_week_start,-21,DAY)
var _pre_three_week_end=DATEADD(_week_start,-15,DAY)
return
IF( HASONEFILTER('Date '[Date]), IF( MAX('test'[Date]) >=_pre_three_week_start && MAX('test'[Date]) <= _pre_three_week_end ,1,0) ,0)
(4)We can put the “isDisplay” measure in the Table or Matrix visual filter. After it ,we configure the filter and click “Apply filter”.
(5)Result: When you select a date in the slice ,we can see the date of the third week before the date we selected.
If this method can't meet your requirement, can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.
If you need pbix, please click here.
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
This seems really close, particulary to define the previous three week start and end date by a variable.
Below is how I'm structuring my custom table. It is simply using fields from a date table.
Once my table is built, I would use a slicer where I filter on the "selection" column in my custom table. I tried to use your variables as they were set up, but I was getting a ciruclar dependency error, so I used the FILTER & DISTINCT solution that worked on my measures. Now I'm getting a "DATEADD" must specify a column error.
The measures in question that you provided are in italics. How do I adjust those to work with the current format? The other measures work.
VAR PYTodayDate =ble in question are in italics
@Alex_LevelUp Sequential makes things like that easy: https://community.powerbi.com/t5/Quick-Measures-Gallery/Sequential/m-p/380231?search-action-id=25265...
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 |
---|---|
49 | |
26 | |
21 | |
15 | |
12 |
User | Count |
---|---|
57 | |
49 | |
44 | |
19 | |
18 |