Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Converting a VBA UDF into DAX

Hi experts,

 

Wondering if someone has already tried to convert a VBA function to DAX? 

 

Function Cover(Stock As Double, Sales As Range) As Double

s = Stock
c = 0

For Each sale In Sales.Cells
If s = 0 Then Exit For
If s >= Val(sale.Value) Then
c = c + 1
s = s - Val(sale.Value)
Else
c = c + s / Val(sale.Value)
s = 0
Exit For
End If
Next

If s > 0 Then c = 9999

Cover = c

End Function

 

Cheers,

 

Gilly

2 Replies