cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
darjicharmi11
New Member

DAX or Power Query

Hi Everyone, 

 

My question is, how do I find the sum of prior qty available in the past 13 weeks starting from today and going back 13 weeks. 
Here is a mock dataset of the main table. This table is further connected to another table called 'Fiscal Calendar table' and is conencted via 'file date column'. 
The method i used is: 

L13W Requested Index = VAR L13R = CALCULATE(SUM(TOTAL REQUESTED (CS)),DATESINPERIOD(File Date,
MAX(File Date),-91,DAY))
VAR L13A = CALCULATE(SUM(PRIOR QTY AVAILABLE RETAIL (CS)),DATESINPERIOD(File Date,
MAX(File Date),-91,DAY))
RETURN
IFERROR(L13R/L13A,1.5)
 
This method doesn't calculate the 13weeks back from today, it takes the max date from the table and goes back 91 days which sometimes goes beyond 14-15 weeks instead of 13weeks. 
Please put your thoughts on this, thank you!
 
SKU Province prior qty available (cases)total requested(cases) total sold(cases)file date 
1AB2010725/02/2022
2AB34272628/03/2022
3AB23131013/04/2022
4AB1211817/05/2022
5AB2217181/6/2022
6AB31282715/07/2022
7AB72120/08/2022
5 REPLIES 5
v-yalanwu-msft
Community Support
Community Support

Hi, @darjicharmi11 ;

Try it.

 

L13W Requested Index = 
VAR L13R = CALCULATE(SUM([total requested(cases) ]),DATESINPERIOD('Table'[file date ],
TODAY(),-91,DAY))
VAR L13A = CALCULATE(SUM([total sold(cases)]),DATESINPERIOD('Table'[file date ],
TODAY(),-91,DAY))
return 
IFERROR(L13R/L13A,1.5)

 

The final show:

AilsaTao_7-1660726947608.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello, 

 

I have already tried using TODAY(), but it gives me a blank result in the coloumn. 

Hi, @darjicharmi11 ;

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

MartijnW
Frequent Visitor

Instead of the MAX filedate, use TODAY(). see this link for a description of the function and its caveats:

https://docs.microsoft.com/en-us/dax/today-function-dax

 

Also, please take a look at the function DIVIDE(). It is considered best practise to avoid divisions using "/". 

 

Martijn

Hi Martijn, 

 

I have already tried TODAY() in place of MAX, but I get a blank data result on doing so.

Helpful resources

Announcements
Difinity Conference

Difinity Conference 2022

Difinity is the largest Microsoft Data, AI, Power BI, Power Platform and Business Applications Conference in New Zealand.

European Share Point Conference

European Share Point Conference

This conference returns live and in-person in Copenhagen this 28 November-01 December with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Microsoft 365 Conference â__ December 6-8, 2022

Microsoft 365 Conference - 06-08 December

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.