Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

Totals not adding up correctly

Hi,

 

Due to missing of data in a stock analysis (certain dates are missing, because only the transaction dates are mentioned in the data), I have created a dax formula to calculate the stock levels at the beginning of each month. Unfortunately, this means that there are huge gaps in my data (for example, data for april 2021 and then 6 months no data untill a new data record of november 2021). I try to fill these gaps with a dax formula which is expressed below. This change to the beginning of the month results in a table that looks like this (very simplified version, there are more than 20k different article numbers and dates vary from 1-1-2021 to 31-12-2024):

ArticlenumberDate Economic stock recalculatedFirst day only

1

1-1-2021 101-1-2021

1

1-3-2021 301-3-2021

1

4-3-2021 50 

2

1-1-2021 10001-1-2021

2

1-3-2021 9001-3-2021

2

4-3-2021 700 

3

1-1-2021 301-1-2021

3

1-3-2021 101-3-2021

3

4-3-2021 60 

3

1-8-2021 801-8-2021

 

 

 

 

Then I have added a new date table including the range of first days of each month from 1-1-2021 untill 31-12-2024. This allows me to build a new visual with the stock per first day of the month (adding the date table column to the X-Axis).

 

To calculate the stock for previous values that are not in the data table, I use the following dax:

 

 

 

 

 

 

Economic stock visual = VAR d =
    SELECTEDVALUE ( 'Date'[Date] )
RETURN
    CALCULATE(
        LASTNONBLANKVALUE('Table1 (4)'[First day only], SUM('Table1 (4)'[Economic stock recalculated])),
        'Table1 (4)'[First day only] <= d,
        CROSSFILTER ( 'Date'[Date], 'Table1 (4)'[First day only], None)
    )

 

 

 

 

 

 

 

All goes well and when I look at the data in a matrix visual it all looks good if I use 1 articlenumber. However, when I add more article numbers and look at the totals and an Area Visual everything goes wrong. It shows the wrong totals and doesn't show me all the different. herewith a screenshot:

Does somebody know how to get the right totals and thus create a right area chart which adds up the different stocks correctly?

 

Thanks in advance.

3 Replies