Forum Discussion

llinasG's avatar
llinasG
Frequent Visitor
2 years ago
Solved

Running total values include in blank rows

I am calculating running totals for PO table grouped by week no-YY

 

Running total PO QTY =

CALCULATE( [SUM of QTY (tonnes)],
FILTER( ALLSELECTED (PO),
PO[Week_No_Year] <= MAX(PO[Week_No_Year])))
 
Calculating SUM of coverage forcast by week no_YY from a different table
 
Calculating DEMAND SUM of PO + Forecast

 

 

Issue:

W49-23 in PO table qty is blank

W49-23 in Forecast table exist

 

I need to calculate DEMAND 145 + 110.80 = 255.80

 

 

  • Thanks for the help I managed to resolve it. I changed the source week no to date, removed additional week no table and linked all my data tables to one date table and this seems to solved the issue.

3 Replies

  • llinasG , I such case always have Date/Week table with all weeks

     

    With date table having yearweek column you can get cumulative like

     

    Cumm Sales = CALCULATE(SUM(Sales[Sales Amount]),filter(all('Date'),'Date'[date] <=max('Date'[date])))

    Cumm Sales = CALCULATE(SUM(Sales[Sales Amount]),filter(allselected(date),date[date] <=max(date[Date])))

    Cumm Based on Date = CALCULATE([Net], Window(1,ABS,0,REL, ALL('date'[date]),ORDERBY('Date'[date],ASC)))

    Cumm Based on Date = CALCULATE([Net], Window(1,ABS,0,REL, ALLSELECTED('date'[date]),ORDERBY('Date'[date],ASC)))


    If you have Year week / week table. create a Week Table(Say date) and add week rank column

     

    Have these new columns in Date Table, Week Rank is Important in Date/Week Table

    Week Rank = RANKX('Date','Date'[Week Start date],,ASC,Dense)
    OR
    Week Rank = RANKX('Date','Date'[Year Week],,ASC,Dense) //YYYYWW format


     

    Cumm Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]<=max('Date'[Week Rank])))

     

     

    Use week from week or date table in visual

     

    Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
    https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5bd4
    To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.


    Power BI — Week on Week and WTD
    https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
    https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-Last-Week/ba-p/1051123
    https://www.youtube.com/watch?v=pnAesWxYgJ8

  • llinasG's avatar
    llinasG
    Frequent Visitor

    Thanks for reply amitchandak , I added week rank table.

    I did not explain my data well in my first post. I will try better now.

     

    I have three tables

     

    PO Table

    PO Date             Target Date         Qty   PlantProduct
    05/09/202305/11/20231.5ARed
    12/09/202307/11/20231.2BBlue
    01/10/202311/11/20232AGreen
    12/10/202302/12/20231.1BBlue
    14/10/202304/12/20230.8BBlue
    01/11/202306/12/20239BRed
    02/11/202305/01/20242AGreen
    05/11/202306/01/20241ABlue
    07/11/202307/01/20241.3BRed

     

    Forecast Table

    Week No - YearTarget Date     QtyPlantProduct
    2023-4201/11/20232ARed
    2023-4401/11/20235BBlue
    2023-4601/11/20236AGreen
    2023-4801/11/20237BBlue
    2023-4201/12/20232BBlue
    2023-4401/12/20235BRed
    2023-4601/12/20236AGreen
    2023-4801/12/20238ABlue
    2023-4201/01/20249BRed
    2023-4401/01/20243ABlue
    2023-4601/01/20242BGreen
    2023-4801/01/20245ARed

     

    Contract Table

    Contract DateTarget MonthQtyPlantProduct
    05/07/202301/11/20235ARed
    20/07/202301/11/20237BBlue
    05/08/202301/11/20236AGreen
    05/09/202301/12/20235BBlue
    06/09/202301/12/20238BBlue
    01/10/202301/01/20242BRed

     

    I am looking to create a line chart visual to show:

     

    Y-axis

    Demand Forecast = Forecast Qty + Running Total PO Qty

    Contracted = Running Total Contract Qty

     

    X-axis

    Forecast Week No

     

    Filters By:

    * Target Month

    * Plant

    * Product

     

     

    To achieve this I created 2 Date Tables and 1 unique week no table

     

    Date Calendar - to link Target Dates and be able to filter by Target Month  (NOV-2023 , DEC-2023 , JAN-2023)

    Week Calendar - to link (PO Date, Contract Date) to filter by Week No

    Distinct Week Calendar - to Link Forecast WeekNo-Year to Week calendar

     

    I calculated running totals Contract Qty and it shows correctly when no filter applied:

     

    When I apply a Target Month Filter it leaves these gaps and the total sum does not include last Qty

     

     

    I am stuck with this issue for a few days now and very close to giving up 🙂

     

  • llinasG's avatar
    llinasG
    Frequent Visitor

    Thanks for the help I managed to resolve it. I changed the source week no to date, removed additional week no table and linked all my data tables to one date table and this seems to solved the issue.