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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
ianboothman84
Helper II
Helper II

Date Period - This week

Good Evening

 

Hope you are well

 

I have a date period slicer on my PBIX and i need to add two more values. 

1. This week

2. last week. 

 

Below is a picture of ny current visual 

ianboothman84_0-1631996545945.png

i have used the below dax as a measure

 

Date Period =
UNION(
ADDCOLUMNS(
{today()},
"Type", "Today",
"Order", 1
),
ADDCOLUMNS(
{today()-1},
"Type", "Yesterday",
"Order", 2
),
ADDCOLUMNS(
DATESMTD('Combined Data'[The Date]),
"Type", "This Month",
"Order", 3
),
ADDCOLUMNS(
DATESYTD('Combined Data'[The Date]),
"Type", "This Year",
"Order", 4
),
ADDCOLUMNS(
DATEADD(DATESMTD('Combined Data'[The Date]),-1,MONTH),
"Type", "Last Month",
"Order", 5
),
ADDCOLUMNS(
PREVIOUSYEAR(DATESYTD('Combined Data'[The Date])),
"Type", "Last Year",
"Order", 6
),
ADDCOLUMNS(
CALENDAR(MIN('Combined Data'[The Date]),MAX('Combined Data'[The Date])),
"Type", "Show All",
"Order", 7
),
ADDCOLUMNS(
CALENDAR(MIN('Combined Data'[The Date]),MAX('Combined Data'[The Date])),
"Type", "Custom",
"Order", 8
)
)
 
Again, i would just like to add two more options. This week, last week
 
Id welcome any help
 
Many Thanks
 
1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@ianboothman84 here is an example on how you can add this and prev week:

 

Date Period = 
VAR __today = TODAY()
VAR __thisWeek = 
    CALENDAR ( 
        __today - ( WEEKDAY( __today ) - 1 ), 
        __today + 7 - ( WEEKDAY ( __today ) ) 
    )
VAR __prevWeek = 
    CALENDAR ( 
        MINX ( __thisWeek, [Date] ) - 7, 
        MAXX ( __thisWeek, [Date] ) - 7 
    )
RETURN
UNION (
    ADDCOLUMNS (
        { __today },
        "Type", "Today",
    "Order", 1
    ),
    ADDCOLUMNS (
        { __today - 1 },
        "Type", "Yesterday",
        "Order", 2
    ),
    ADDCOLUMNS (
        __thisWeek,
        "Type", "This Week",
        "Order", 3        
    ),
    ADDCOLUMNS (
        __prevWeek,
        "Type", "Prev Week",
        "Order", 4     
    )
)

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

3 REPLIES 3
ianboothman84
Helper II
Helper II

@parry2k  thank you for your quick reply. this has worked out great . 

 

parry2k
Super User
Super User

@ianboothman84 here is an example on how you can add this and prev week:

 

Date Period = 
VAR __today = TODAY()
VAR __thisWeek = 
    CALENDAR ( 
        __today - ( WEEKDAY( __today ) - 1 ), 
        __today + 7 - ( WEEKDAY ( __today ) ) 
    )
VAR __prevWeek = 
    CALENDAR ( 
        MINX ( __thisWeek, [Date] ) - 7, 
        MAXX ( __thisWeek, [Date] ) - 7 
    )
RETURN
UNION (
    ADDCOLUMNS (
        { __today },
        "Type", "Today",
    "Order", 1
    ),
    ADDCOLUMNS (
        { __today - 1 },
        "Type", "Yesterday",
        "Order", 2
    ),
    ADDCOLUMNS (
        __thisWeek,
        "Type", "This Week",
        "Order", 3        
    ),
    ADDCOLUMNS (
        __prevWeek,
        "Type", "Prev Week",
        "Order", 4     
    )
)

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

hi @parry2k 

 

 i have just used my report and filtered to This month, its returning no data as it thinks we are already in October. From the above code, can you see the reason why?

last  month only returns 1/9/21

 

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.