Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
I have the following data model:
With this model I’m reporting the 30 and 90 day Inventory values:
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.
Solved! Go to Solution.
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.
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.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 50 | |
| 44 | |
| 42 | |
| 19 | |
| 19 |
| User | Count |
|---|---|
| 69 | |
| 68 | |
| 32 | |
| 32 | |
| 32 |