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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
LarryDunn
Regular Visitor

Divide Function Not Working

I have the following data model:

 

Data model.jpg

 

With this model  I’m reporting the 30 and 90 day Inventory values:

 

Inventory.jpg

 

 

With this data I need to calculate Beginning /Ending/Previous/Current/Average Inventory values, Purchases During Period, COGS and Inventory Turns.

 

These calculations are as follows:

 

Beginning Inventory = CALCULATE( SUM(Inventory_Detail_Fact[Best_Cost]) , DATESBETWEEN(Date_Dim[Datekey], SELECTEDVALUE(CurrentStartDate[Date]), SELECTEDVALUE(CurrentStartDate[Date]) ))

 

Ending Invenory = CALCULATE( SUM(Inventory_Detail_Fact[Best_Cost]) , DATESBETWEEN(Date_Dim[Datekey], SELECTEDVALUE(CurrentEndDate[Date]), SELECTEDVALUE(CurrentEndDate[Date])))

 

Previous Inventory 30 = CALCULATE( SUM( Inventory_Detail_Fact[Best_Cost] ) , DATESBETWEEN(Date_Dim[Datekey],

                         SELECTEDVALUE('Start Date'[Date]), SELECTEDVALUE('End Date Previous'[Date])))

 

Current Inventory = CALCULATE( SUM( Inventory_Detail_Fact[Best_Cost] ) , DATESBETWEEN(Date_Dim[Datekey],

                          SELECTEDVALUE(CurrentStartDate[Date]), SELECTEDVALUE(CurrentEndDate[Date])))

 

Average Inventory = DIVIDE( ( [Current Inventory] + [Previous Inventory 30] ) , 2 , 0)

 

Purchases During Period = CALCULATE( SUM( Inventory_Detail_Fact[Best_Cost] ) , Inventory_Detail_Fact[Transaction_Type_Dim_Id] = 3 || Inventory_Detail_Fact[Transaction_Type_Dim_Id] = 2 ,

                                     DATESBETWEEN(Date_Dim[Datekey],

                                     SELECTEDVALUE(CurrentStartDate[Date]), SELECTEDVALUE(CurrentEndDate[Date])))

 

COGS = [Beginning Inventory] + [Purchases During Period] - [Ending Invenory]

 

 

Inventory Turns = DIVIDE([COGS] , [Average Inventory] , 0)

 

 

Everything works fine until I attempt to calculate Inventory Turns.  When the Average Inventory is zero the Divide function does not return 0 as coded above and I get erroneously large results and infinity.

 

Any help would be appreciated.

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

Hi @LarryDunn 

Create this measure instead

Inventory Turns =
IF ( [Average Inventory] = 0, 0, DIVIDE ( [COGS], [Average Inventory], 0 ) )

Best Regards
Maggie

 

Community Support Team _ Maggie Li
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

1 REPLY 1
v-juanli-msft
Community Support
Community Support

Hi @LarryDunn 

Create this measure instead

Inventory Turns =
IF ( [Average Inventory] = 0, 0, DIVIDE ( [COGS], [Average Inventory], 0 ) )

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.