Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MDX syntax for IF statement

Status
Not open for further replies.

ettienne

Programmer
Oct 29, 2005
3,388
0
36
US
I have the following code which adds some fields to a Pivottable:

Set ptView = PivotTable.ActiveView

' The following lines of code add fields to the row area and data areas of the PivotTable list. ptView.RowAxis.InsertFieldSet ptView.FieldSets("CATEGORY")

ptView.DataAxis.InsertTotal ptView.AddTotal("Sales", ptView.FieldSets("Sales").Fields(0), PivotTable.Constants.plFunctionSum)

ptView.DataAxis.InsertTotal ptView.AddTotal("Cost", ptView.FieldSets("Cost").Fields(0), PivotTable.Constants.plFunctionSum)

ptView.DataAxis.InsertTotal ptView.AddTotal("Margin", ptView.FieldSets("Margin").Fields(0), PivotTable.Constants.plFunctionSum)

ptView.DataAxis.InsertTotal ptView.AddCalculatedTotal("Marginp", "Margin%", "([Measures].[Margin]/[Measures].[Sales])")

The last line works fine if [Measures].[Sales] <> 0, but I cannot figure out the correct syntax for the IF statement:
IF [Measures].[Sales] <> 0 THEN [Measures].[Margin]/[Measures].[Sales] ELSE 0
 
Don't worry, got it:

IIf([Measures].[Sales]=0,0,[Measures].[Margin]/[Measures].[Sales])

IF and IFF don't work...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top