Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago

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

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Martijn, 

       

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

  • v-yalanwu-msft's avatar
    v-yalanwu-msft
    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:


    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's avatar
      Anonymous
      Not applicable

      Hello, 

       

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

      • v-yalanwu-msft's avatar
        v-yalanwu-msft
        Community Support

        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.