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
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)

View solution in original post

4 REPLIES 4
v-stephen-msft
Community Support
Community Support

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)

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.

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
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.