Forum Discussion
Swimming Season Filter
- 1 year ago
Yes, that's very possible. Typically I would create a disconnected table to grab user inputs. As an example, you would build a similar table to this:
SwimSeasons = DATATABLE( "Season", STRING, "Start", DATETIME, "End", DATETIME, { { "Swim 23/24", "11/1/2023", "4/30/2024" }, { "Swim 24/25", "11/1/2024", "4/30/2025" } } )
Although you may want to make it a bit more dynamic but you'll need at least 3 columns. The season name, season start and end dates.
Then, all that's left is to retrieve the season start and end dates in your analysis.SeasonStart = // Retrieve current season in scope VAR _Season = SELECTEDVALUE(SwimSeasons[Season], MAX(SwimSeasons[Season])) // Retrieve start date VAR _Start = CALCULATE(MAX(SwimSeasons[Start]), SwimSeasons[Season] = _Season) // Retrieve end date VAR _End = CALCULATE(MAX(SwimSeasons[End]), SwimSeasons[Season] = _Season) RETURN // debug result. Use start and end date in analysis _Season & " | " & _Start & " | " & _EndThe dates that you return would then be the ones you would want to query against your date table:
- Anonymous1 year ago
Do you have a Date or Calendar table in the model? If not, I'd suggest adding a Date table to the model. Create a relationship on Date column between the Date table and the Fact table. Then in the Date table, add a "Season" column with below DAX. Place the Season column into a slicer. Now you will be able to filter data with this slicer based on Seasons.
Season = VAR vMonth = MONTH([Date]) VAR vYear = FORMAT([Date], "yy") RETURN SWITCH(TRUE(), vMonth>=11, vYear & "/" & vyear+1, vMonth<=4, vYear-1 & "/" & vYear, BLANK() )Hope this would be helpful.
Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!
Yes, that's very possible. Typically I would create a disconnected table to grab user inputs. As an example, you would build a similar table to this:
SwimSeasons =
DATATABLE(
"Season", STRING,
"Start", DATETIME,
"End", DATETIME,
{
{
"Swim 23/24", "11/1/2023", "4/30/2024"
},
{
"Swim 24/25", "11/1/2024", "4/30/2025"
}
}
)
Although you may want to make it a bit more dynamic but you'll need at least 3 columns. The season name, season start and end dates.
Then, all that's left is to retrieve the season start and end dates in your analysis.
SeasonStart =
// Retrieve current season in scope
VAR _Season = SELECTEDVALUE(SwimSeasons[Season], MAX(SwimSeasons[Season]))
// Retrieve start date
VAR _Start = CALCULATE(MAX(SwimSeasons[Start]), SwimSeasons[Season] = _Season)
// Retrieve end date
VAR _End = CALCULATE(MAX(SwimSeasons[End]), SwimSeasons[Season] = _Season)
RETURN
// debug result. Use start and end date in analysis
_Season & " | " & _Start & " | " & _End
The dates that you return would then be the ones you would want to query against your date table: