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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
M_MELLEMA
Frequent Visitor

Dax formula - do not show the last two weeks in visual

Hi,

 

I have a visual with weeks and hours:

M_MELLEMA_0-1706868336849.png

M_MELLEMA_1-1706868420998.png

 I don't want to show the last two weeks in the visual. So in this case I only want to see week 1,2,3 not week 4 and 5.

weeknr is a created column: 

M_MELLEMA_2-1706868511000.png

I've tried a couple things but I'm not an experted to DAX. So I hope someone can help me.

 

 

 

1 ACCEPTED SOLUTION

Solution:

Add a column Currentweek = WEEKNUM(today())

Add another column Notlasttwoweeks = IF((Datumtabel[Huidige_week]-Datumtabel[weeknr])<2,1,0)

 

Put the column Notlasttwoweeks in the filter of the visual.

 

View solution in original post

14 REPLIES 14
Anonymous
Not applicable

Hi @M_MELLEMA ,
You can try changing the previous metric to something like the following, which will dynamically remove the last two weeks.

Measure = 
VAR max_week = CALCULATE(MAX('Table'[weeknr]),ALL('Table'))
return
IF(MAX('Table'[weeknr]) <= max_week - 2,MAX('Table'[value]),BLANK())

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

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

Hi @Anonymous 

I've tried this measure and put it in the values of the visual. But I still see all weeks.

M_MELLEMA_1-1707470841419.png

 

M_MELLEMA_2-1707470895217.pngM_MELLEMA_3-1707471042628.png

 


 

Solution:

Add a column Currentweek = WEEKNUM(today())

Add another column Notlasttwoweeks = IF((Datumtabel[Huidige_week]-Datumtabel[weeknr])<2,1,0)

 

Put the column Notlasttwoweeks in the filter of the visual.

 

That won't work in the first two weeks of January.

I think that when it's week 1 or week 2, the user doesn't see any results. But I have a button that will show all weeks.

 

M_MELLEMA_0-1707918944865.png

What do you suggest? 

 

Use YearWeek instead of Week number, and then TOPN(2) over all yearweeks that are smaller than the current value.

Anonymous
Not applicable

Hi @M_MELLEMA ,

1.you can create a measure value by writing the following expression.

Measure = IF(MAX('Table'[weeknr]) < 4,MAX('Table'[value]),BLANK())

2.The result obtained is shown below.

vkaiyuemsft_0-1707100680321.png

You can also choose not to use measure. You can do this by going to filters on the right hand side of the report, selecting the weeknr column you want to change, making the value less than or equal to 3, and then selecting Apply filter.

vkaiyuemsft_1-1707100680324.png

You can also change the Filter type to Top N, drag the data to be filtered into By value, and select Apply filter.

vkaiyuemsft_2-1707100737072.png

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

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

 

Hi Clara,

 

The filter is working, but I want it dynamically.  Whatever week it is, I don't want to see the last 2 weeks.

Let's say it's week 10, then I don't want to see weeks 9 and 10. Let's say it's week 14, then I don't want to see weeks 12 and 13.

M_MELLEMA_0-1707136880784.pngM_MELLEMA_1-1707136942412.png

 

I've tried the measure: 

M_MELLEMA_2-1707137073241.png

that's working to, but is also not dynamically.  How can I make it dynamically?

How would that work in the first week of the new year?

 

You need a "YearWeek" number,  and this is where stuff gets weird very fast. Weeks are incompatible with years and months.  Your only true solution is an external reference table where YOU define what the week number is for each day of each year.  

 

- grab TODAY()'s yearweek number

- find all yearweek numbers smaller than that, sort descending

- chop off the TOPN2

- use the rest as filter.

I'm using a referencedb already:
 
M_MELLEMA_0-1707142099715.png

 

I don't see a yearweek number column.

You're right. This are the field that are available in our referencedb:

M_MELLEMA_0-1707144543643.png

I can create a new column year-weeknumber.

yes, that is my recommendation.

lbendlin
Super User
Super User

I recommend you use an externally sourced calendar table that already has the week numbers prepopulated.

 

Create a measure filter that excludes dates greater than TODAY()-14 .

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.