Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
I would like to create a measure which will calculate sales for previous period based on choosen granularity.
I followed: https://www.youtube.com/watch?v=hilfglpKNRQ to create granularity and slicer.
first table is connected with slicer with visual table and this table should recalculate appropriately the sales for previous period based on selection.
I started to create a measure:
Sales Previous Period =
VAR SelectedType = SELECTEDVALUE('hlp_Dynamic Date Selections'[Type])
RETURN
SWITCH(
TRUE(),
SelectedType = "Y",
CALCULATE(
[Sales]
)
)but when I refer to dimCalendar or use time intelligence functions the result does not show. How to achieve such functionality?
https://drive.google.com/file/d/15UslwRjGZy-yEifeGWuSPq7_BPcB_yV-/view?usp=sharing
Solved! Go to Solution.
You need to remove the filters on the helper table as well as manipulating the dates in the date table.
Sales Previous Period =
VAR SelectedType = SELECTEDVALUE('hlp_Dynamic Date Selections'[Type])
VAR PrevYear = DATEADD( dimCalendar[Date], -1, YEAR )
VAR PrevQuarter = DATEADD( dimCalendar[Date], -1, QUARTER )
VAR PrevMonth = DATEADD( dimCalendar[Date], -1, MONTH )
VAR PrevWeek = DATEADD( dimCalendar[Date], -7, DAY )
VAR PrevDay = DATEADD( dimCalendar[Date], -1, DAY )
VAR Result = SWITCH( SelectedType,
"Y",
CALCULATE(
[Sales],
PrevYear,
REMOVEFILTERS( 'hlp_Dynamic Date Selections' )
),
"Q",
CALCULATE(
[Sales],
PrevQuarter,
REMOVEFILTERS( 'hlp_Dynamic Date Selections' )
),
"M",
CALCULATE(
[Sales],
PrevMonth,
REMOVEFILTERS( 'hlp_Dynamic Date Selections' )
),
"W",
CALCULATE(
[Sales],
PrevWeek,
REMOVEFILTERS( 'hlp_Dynamic Date Selections' )
),
"D",
CALCULATE(
[Sales],
PrevDay,
REMOVEFILTERS( 'hlp_Dynamic Date Selections' )
)
)
RETURN Result
You need to remove the filters on the helper table as well as manipulating the dates in the date table.
Sales Previous Period =
VAR SelectedType = SELECTEDVALUE('hlp_Dynamic Date Selections'[Type])
VAR PrevYear = DATEADD( dimCalendar[Date], -1, YEAR )
VAR PrevQuarter = DATEADD( dimCalendar[Date], -1, QUARTER )
VAR PrevMonth = DATEADD( dimCalendar[Date], -1, MONTH )
VAR PrevWeek = DATEADD( dimCalendar[Date], -7, DAY )
VAR PrevDay = DATEADD( dimCalendar[Date], -1, DAY )
VAR Result = SWITCH( SelectedType,
"Y",
CALCULATE(
[Sales],
PrevYear,
REMOVEFILTERS( 'hlp_Dynamic Date Selections' )
),
"Q",
CALCULATE(
[Sales],
PrevQuarter,
REMOVEFILTERS( 'hlp_Dynamic Date Selections' )
),
"M",
CALCULATE(
[Sales],
PrevMonth,
REMOVEFILTERS( 'hlp_Dynamic Date Selections' )
),
"W",
CALCULATE(
[Sales],
PrevWeek,
REMOVEFILTERS( 'hlp_Dynamic Date Selections' )
),
"D",
CALCULATE(
[Sales],
PrevDay,
REMOVEFILTERS( 'hlp_Dynamic Date Selections' )
)
)
RETURN Result
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
Check out the November 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 20 | |
| 10 | |
| 9 | |
| 4 | |
| 4 |
| User | Count |
|---|---|
| 32 | |
| 31 | |
| 18 | |
| 12 | |
| 11 |