Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
APM
Helper I
Helper I

Toggling between yesterday and month-to-date data with a 445 calendar date table

Hello,


I'm having a really hard time delivering something my company needs for daily reporting (and feeling the pressure! I'm entirely new to BI). I would really appreciate the help.

 

I am building a dashboard in which sales data is pulled in and populates the below fields:

 

APM_0-1623268159927.png

 

 

What I need to build - a slicer in which I can select:

 

  • Yesterday
  • Last week (Sunday-Saturday format)
  • Month-to-Date 

...and the corresponding data would populate the visual for that time frame.

 

This is complicated by the fact that we use a 445 calendar, and always compare Mondays to Mondays and Tuesdays to Tuesdays (etc) when looking at the data YOY.

 

So, If I select "yesterday", it will show 6/8/2021 data under This Year Sales and 6/9/2020 data under LY Sales. For month, it would show 5/30-6/8 for 2021 and 5/31-6/9 for 2020. I already built the 445 date table (formula is below the post), but need help building the slicer.

 

Any ideas? Thanks!

 

Date table formula:

 

 

Date = VAR vSundays =
{
DATE ( 2020, 04, 05 ),
DATE ( 2021, 04, 04 ),
DATE ( 2022, 04, 03 ),
DATE ( 2023, 04, 03 )
}
VAR vCalendar =
CALENDAR ( MINX ( vSundays, [Value] ), MAXX ( vSundays, [Value] ) - 1 )
VAR vAddDay =
ADDCOLUMNS (
vCalendar,
"Day",
VAR vFirstDOY =
MAXX ( FILTER ( vSundays, [Value] <= [Date] ), [Value] )
RETURN
DATEDIFF ( vFirstDOY, [Date], DAY ) + 1
)
VAR vAddYearWeek =
ADDCOLUMNS (
vAddDay,
"Year",
YEAR ( MAXX ( FILTER ( vSundays, [Value] <= [Date] ), [Value] ) ) + 1,
"Week", ROUNDUP ( [Day] / 7, 0 )
)
VAR vAddMonth =
ADDCOLUMNS (
ADDCOLUMNS (
vAddYearWeek,
"MonthNum",
SWITCH (
TRUE (),
[Week] <= 4, 4,
[Week] <= 8, 5,
[Week] <= 13, 6,
[Week] <= 17, 7,
[Week] <= 21, 8,
[Week] <= 26, 9,
[Week] <= 30, 10,
[Week] <= 34, 11,
[Week] <= 39, 12,
[Week] <= 43, 1,
[Week] <= 47, 2,
[Week] <= 52, 3
)
),
"Month", FORMAT ( DATE ( 2020, [MonthNum], 1 ), "MMMM" )
)
RETURN
vAddMonth
 
..and what the date table looks like:

APM_0-1623267970548.png

 

 

1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @APM ,

 

The easiest way is to use relative date slicer: https://docs.microsoft.com/en-us/power-bi/visuals/desktop-slicer-filter-date-range.

Also you can write DAX to solve: https://www.linkedin.com/pulse/custom-range-date-slicer-power-bi-dynamic-defaults-more-a%C5%9F%C4%B1...

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-stephen-msft
Community Support
Community Support

Hi @APM ,

 

The easiest way is to use relative date slicer: https://docs.microsoft.com/en-us/power-bi/visuals/desktop-slicer-filter-date-range.

Also you can write DAX to solve: https://www.linkedin.com/pulse/custom-range-date-slicer-power-bi-dynamic-defaults-more-a%C5%9F%C4%B1...

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.