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

Get Fabric certified for FREE! Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

How to use Datediff in measure

MaterialDate Quantity

a

12/08/2021152
a13/08/2021748
b14/08/2021631
b15/08/2021421
b16/08/202117
c17/08/2021325
c18/08/2021-793
c19/08/2021-20
e15/10/2021-40
e16/10/2021-451
e17/10/2021-179
b18/10/2021832
a19/10/20211287
a20/10/2021-23
a21/10/202117
c22/10/202137
c23/10/2021-76
c24/10/202137

 

I want to create a measure to create an if else statement to find the values where Quantity is negative and the week difference between today and Date column is less than or equal to 6. I can create a column using the following measure: This works but creates duplications when I use it in matrix visual.

 

Stock = MINX(data,data[Quantity])
Date Diff = WEEKNUM(data[Date])-WEEKNUM(TODAY())
Short 6 Weeks Column = IF([Stock]<=0 && (data[Date Diff] >=0 && data[Date Diff]<=6),1,0)

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Try measure like

 

measure =
var _1= calculate(MIN(data[Quantity]), filter(allselected(data), date[Material] = max(Data[Material]) && datediff(data[Date], today(), day)/7 <=6 ))
return
if(isblank(_1),1,0)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @Anonymous ,

 

Try to use DATEDIFF function, the measure is

Measure = IF(DATEDIFF(TODAY(),MAX('Table'[Date ]),WEEK)<=6&&MAX('Table'[Quantity])<0,1,0)

14.png

 

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.

amitchandak
Super User
Super User

@Anonymous , Try measure like

 

measure =
var _1= calculate(MIN(data[Quantity]), filter(allselected(data), date[Material] = max(Data[Material]) && datediff(data[Date], today(), day)/7 <=6 ))
return
if(isblank(_1),1,0)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi @amitchandak this is working but the problem is that it always starts from the first date of Date column chich varies based on our slicers values. I want the measure to start counting from today and 6 weeks a head all the time. For example, if the date starts from two weeks a head from now, then this measure will show me all values 6 weeks starting from the two weeks, which is wrong. I want to show the first 6 weeks of time at all time if possible.

Kumail
Impactful Individual
Impactful Individual

Hello @Anonymous

 

If you could send sample .pbix that demonstrate what you are looking to get. It would really help providing you a quick solution.
 
You can send the sample .pbix file by adding it to your drive or dropbox and add the link here. 
 
Regards
Kumail Raza

Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.