Hi all!!

I'm new to SSAS Tabular Mode and DAX and I was wondering if anyone could help me, please.

I have to create a Measure that uses different formulas accordingly to the Client and Date dimensions.

For instance, I have a Measure named ServiceLevel like below:

```
ServiceLevel := CALCULATE( DIVIDE ( [SumMeasureA], [SumMeasureB], 0 ) )
```

But the way this ServiceLevel is calculated differs from client to client.

For instance, Client 1 uses the formula

```
Client1ServiceLevel := CALCULATE( DIVIDE ( [SumMeasureA], [SumMeasureB], 0 ) )
```

But Client 2 uses the formula

```
Client2ServiceLevel := CALCULATE( DIVIDE ( [SumMeasureA], [SumMeasureB] - [SumMeasureC], 0 ) )
```

And there is more to that equation. If Client 1 decides to change the way they calculate ServiceLevel on 2020-08-01. to something like DIVIDE ( [SumMeasureA], [SumMeasureB] + [SumMeasureC], 0 )

In case this happens, I need to keep history of the ServiceLevel for each client.

So if the service level report is run for dates previous to 2020-08-01, It should use the old formula for Client1, and after 2020-08-01 I should use the new formula.

So It would be something like this

```
Client1ServiceLevel :=
CALCULATE (
IF (
MAX ( 'FactTable'[DateId] ) <= 20200801,
DIVIDE ( [SumMeasureA], [SumMeasureB], 0 ),
DIVIDE ( [SumMeasureA], [SumMeasureB] + [SumMeasureC], 0 )
)
)
```

The question is, how could I build a report like below

```
Client Date Service level ServiceLevelFormula (wont be in the report, just to explain)
1 2020-07-31 80% DIVIDE ( [SumMeasureA], [SumMeasureB], 0 )
1 2020-08-01 87% DIVIDE ( [SumMeasureA], [SumMeasureB], 0 )
1 2020-08-02 92% DIVIDE ( [SumMeasureA], [SumMeasureB] + [SumMeasureC], 0 )
2 2020-07-31 76% DIVIDE ( [SumMeasureA], [SumMeasureB] - [SumMeasureC], 0 )
2 2020-08-01 89% DIVIDE ( [SumMeasureA], [SumMeasureB] - [SumMeasureC], 0 )
2 2020-07-31 97% DIVIDE ( [SumMeasureA], [SumMeasureB] - [SumMeasureC], 0 )
```

I would need one single ServiceLevel Measure, right?

So I did it like below:

```
ServiceLevel :=
CALCULATE (
SWITCH (
MAX ( 'FactTable'[Client_ID] ),
1, IF (
MAX ( 'FactTable'[DateId] ) <= 20200801,
DIVIDE ( [SumMeasureA], [SumMeasureB], 0 ),
DIVIDE ( [SumMeasureA], [SumMeasureB] + [SumMeasureC], 0 )
),
2, DIVIDE ( [SumMeasureA], [SumMeasureB] - [SumMeasureC], 0 ),
DIVIDE ( [SumMeasureA], [SumMeasureB] , 0 )
)
)
```

It worked, but I have the feeling this could become a mess within time as we get more clients and different service levels formulas.

Would you have any suggestions on a better way to implement this?