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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

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, @Anonymous ;

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.

Anonymous
Not applicable

Hello, 

 

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

Hi, @Anonymous ;

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

Anonymous
Not applicable

Hi Martijn, 

 

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

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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