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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

DAX Help

Needs to calculate Last 12 months average inventory

 

Days of Inventory in Hand (DIH) =  Average Inventory / Average daily Net Sales.

 

Now how to arrive average inventory:

 

From the selected date by user say 04.06.2020, go backward and check inventory value on 04.06.20, 04.05.20…………….. 04.07.19 (12 months)

Add all twelve months inventory and divide it by 12 so that you will get average inventory.

 

Average daily net sales =  say selected date 04.06.20 then ( Net sales from 04.07.19 to 04.06.20 (12 months) divide it by 12)              

 

Guys please help on this

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

Hi,

 

Did you have a calendar table with relationship with your fact table?

 

You can use the following dax to calculted rolling average inventory for last 12 months:

 

measure =
VAR _DATE =
    SELECTEDVALUE ( 'Date'[Date] )
RETURN
    CALCULATE (
        SUM ( 'Table'[Inventory] ),
        DATESBETWEEN ( 'Date'[Date], DATEADD ( _DATE, -12, MONTH ), _DATE )
    ) / 12

 

It will be the same for Net Sales. Or you can use quick measure in power bi to calculate rolling average. Please refer to https://www.mssqltips.com/sqlservertip/5635/creating-a-rolling-average-graph-with-power-bi/.

 

It will be nice if you can show us some sample data by onedrive for business.

 

Best Regards,

Dedmon Dai

View solution in original post

5 REPLIES 5
v-deddai1-msft
Community Support
Community Support

Hi,

 

Did you have a calendar table with relationship with your fact table?

 

You can use the following dax to calculted rolling average inventory for last 12 months:

 

measure =
VAR _DATE =
    SELECTEDVALUE ( 'Date'[Date] )
RETURN
    CALCULATE (
        SUM ( 'Table'[Inventory] ),
        DATESBETWEEN ( 'Date'[Date], DATEADD ( _DATE, -12, MONTH ), _DATE )
    ) / 12

 

It will be the same for Net Sales. Or you can use quick measure in power bi to calculate rolling average. Please refer to https://www.mssqltips.com/sqlservertip/5635/creating-a-rolling-average-graph-with-power-bi/.

 

It will be nice if you can show us some sample data by onedrive for business.

 

Best Regards,

Dedmon Dai

Anonymous
Not applicable

But my client is asking average inventory calculation like below

 

From the selected date by user say 04.06.2020,

go backward and check inventory value on 04.06.20, 04.05.20…………….. 04.07.19 (12 months)

Add all twelve months inventory and divide it by 12 so that you will get average inventory.

Hi @Anonymous ,

 

Please see my edited reply.

 

Best Regards,

Dedmon Dai

 

amitchandak
Super User
Super User

@Anonymous , with a date calendar

 


Rolling 12 = CALCULATE(Average(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(Sales[Sales Date]),-12,MONTH))
Rolling 12 = CALCULATE(Average(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX(Sales[Sales Date]),-12,MONTH))

 

Or First Sum at month level and then take Avg

 

Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(Sales[Sales Date]),-12,MONTH))
Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX(Sales[Sales Date]),-12,MONTH))

Avg Rolling 12 = AverageX(summarize(Sales,Date[Month Year],"_1",[Rolling 12]),[_1])

Or [Rolling 12]/12

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

In my case, the user will select one date, and I have to average inventory based on that date.

Days of Inventory in Hand (DIH) =  Average Inventory / Average daily Net Sales.

 

Now how to arrive average inventory:

 

From the selected date by user say 04.06.2020, go backward and check inventory value on 04.06.20, 04.05.20…………….. 04.07.19 (12 months)

Add all twelve months inventory and divide it by 12 so that you will get average inventory.

 

Average daily net sales =  say selected date 04.06.20 then ( Net sales from 04.07.19 to 04.06.20 (12 months) divide it by 12)              

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors