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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
tzanouman
Frequent Visitor

Days of Stock - dax calculation

Hello team, 

I want your support please regarding the Days of Stock calculation. The calculation should be: 

Ending Stock / sum(of next 4 weeks Total Stock)*30. 

Any idea what the formula can be for each cell to get dynamically the sum of the next 4 weeks of Total stock?

 

CodeIDWeekTOTAL STOCKENDING STOCKDays of Stock
80294620240145852400 
80294620240235002400?
80294620240330002400?
80294620240425002400?
80294620240515002400?
80294620240610002500?
80294620240750004000?
80294620240845854000?
80294620240935004000?
80294620241030002400?
80294720240145852400 
80294720240235002400?
80294720240330002400?
80294720240425002400?
80294720240515002400?
80294720240610002500?
80294720240750004000?
80294720240845854000?
80294720240935004000?
80294720241030002400?

 

Thanks in advance,

Manolis

1 ACCEPTED SOLUTION
v-zhengdxu-msft
Community Support
Community Support

Hi @tzanouman 

 

please try this:

First of all, I create a index column in Power Query:

vzhengdxumsft_0-1706856007523.png

Then I create a calculate column:

Days of Stock = 
VAR _4Days = FILTER(
                'Table',
                'Table'[Index]<EARLIER('Table'[Index])+5
                &&
                'Table'[CodeID]=EARLIER('Table'[CodeID]
                )
            )
VAR _1Days = FILTER(
                'Table',
                'Table'[Index]<EARLIER('Table'[Index])+1
                &&
                'Table'[CodeID]=EARLIER('Table'[CodeID]
                )
            )
RETURN IF(
        CALCULATE(SUM('Table'[TOTAL STOCK]),
        FILTER(
            'Table',
            'Table'[Index]=EARLIER('Table'[Index])+4
            &&
            'Table'[CodeID]=EARLIER('Table'[CodeID])))<>BLANK(),
            SUMX(
                _4Days,
                'Table'[TOTAL STOCK]
            )
            -
            SUMX(
                _1Days,
                'Table'[TOTAL STOCK]
            )
        )

The result is as follow:

vzhengdxumsft_1-1706856177686.png

 

Best Regards,

Zhengdong Xu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-zhengdxu-msft
Community Support
Community Support

Hi @tzanouman 

 

please try this:

First of all, I create a index column in Power Query:

vzhengdxumsft_0-1706856007523.png

Then I create a calculate column:

Days of Stock = 
VAR _4Days = FILTER(
                'Table',
                'Table'[Index]<EARLIER('Table'[Index])+5
                &&
                'Table'[CodeID]=EARLIER('Table'[CodeID]
                )
            )
VAR _1Days = FILTER(
                'Table',
                'Table'[Index]<EARLIER('Table'[Index])+1
                &&
                'Table'[CodeID]=EARLIER('Table'[CodeID]
                )
            )
RETURN IF(
        CALCULATE(SUM('Table'[TOTAL STOCK]),
        FILTER(
            'Table',
            'Table'[Index]=EARLIER('Table'[Index])+4
            &&
            'Table'[CodeID]=EARLIER('Table'[CodeID])))<>BLANK(),
            SUMX(
                _4Days,
                'Table'[TOTAL STOCK]
            )
            -
            SUMX(
                _1Days,
                'Table'[TOTAL STOCK]
            )
        )

The result is as follow:

vzhengdxumsft_1-1706856177686.png

 

Best Regards,

Zhengdong Xu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi v-zhengdxu-msft.

 

It works perfectly, thank you very much for your help, it is much appreciated! 

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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