Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
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
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 8 | |
| 6 | |
| 6 | |
| 5 | |
| 4 |
| User | Count |
|---|---|
| 25 | |
| 15 | |
| 8 | |
| 8 | |
| 8 |