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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
adityo
Frequent Visitor

Get Current Week based on two conditions (Max Year and Max Week) based on selected filter

Hi,

I wanto to created Current Week based on the Max Selected Year and Month, and the previous Week based on the Min Selected Year and Month. like this

adityo_0-1628555379955.png

i already created measure for Current week like this :

Current Week =
Var _Max = MAXX(allselected(AP_Database[Week]), AP_Database[Week])
RETURN
CALCULATE(SUM(AP_Database[Amount in local cur.]), filter(AP_Database,AP_Database[Week]=_max))
 
and 
Previous Week =
Var _Min = MINX(allselected(AP_Database[Week]), AP_Database[Week])
RETURN
CALCULATE(SUM(AP_Database[Amount in local cur.]), filter(AP_Database, AP_Database[Week]=_min))

 

but the result comes like this

adityo_1-1628555581603.png

 

 

 

1 ACCEPTED SOLUTION

@adityo Well done, you're getting close. You'll need to add a Week Number column to your date table also, this can be done in Power Query. 

 

AllisonKennedy_0-1628740391397.png

 

Then, see if this blog helps: Calculating Weekly Sales w/DAX In Power BI | Enterprise DNA

 

Finally come back and let me know how you're getting on and what further questions you still have. 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

6 REPLIES 6
AllisonKennedy
Super User
Super User

@adityo You'll need to create a Week Offset or Year Week merged column that tells Power BI to put Week 53 of the previous year before Week 1 of this year. Radacad have a simple starting script to help with this https://radacad.com/offset-columns-for-the-date-table-flexibility-in-relative-date-filtering-for-pow... 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Hi @AllisonKennedy 

could you give example how to do this, or could you modify from my measure, because I'm sure, the data model is different.

Thank you

@adityo  Yes, the data model is different, that's the issue. You need to add a column to your data model. You need to build a date table. The link I provided has a link to download a txt file you can use for the date table you'll need. 

 

Here's my blog on why you need Date table: https://excelwithallison.blogspot.com/2020/04/dimdate-what-why-and-how.html but it doesn't include the Offset column you need. 

 

So download the M advanced editor from here: https://radacad.com/download/13519/ 

 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Hi @AllisonKennedy ,

Im totally newbie here, here the screenshot what i do,

i created the table and linked it, what is the next steps?

adityo_1-1628582846268.png

 

 

@adityo Well done, you're getting close. You'll need to add a Week Number column to your date table also, this can be done in Power Query. 

 

AllisonKennedy_0-1628740391397.png

 

Then, see if this blog helps: Calculating Weekly Sales w/DAX In Power BI | Enterprise DNA

 

Finally come back and let me know how you're getting on and what further questions you still have. 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

thank you so much @AllisonKennedy it works perfectly 👍🏻

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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