Power Pivot Measure If Statement giving incorrect value

misstoffeepenny

New Member
Joined
Jan 18, 2021
Messages
19
Office Version
  1. 365
  2. 2016
  3. 2011
Platform
  1. Windows
Hi all,
I have a measure if statement to calculate the AAFR based on the different companies for YTD. When I set the filter to 'Maine Group' it calculates the correct value, when I select 'Smyth Steel' it calculates the correct value however if I don't filter the data I get a value approx. 10x the correct value. Can anyone help me debug my formula?

NB all my relationships are correct in my data model, it's just the math that isn't working. Also note these are the only 2 current companies in the company table.

formula:
IF(
MAX('Company'[Company]) = "Maine Group",
CALCULATE(
(COUNT('Ext Accident Log'[Injury Type]) / AVERAGE(EmployeeCount[Maine Employee Count]) * 100000),
DATESYTD('Calendar'[Date])
),
IF(
MAX('Company'[Company]) = "Smyth Steel",
CALCULATE(
(COUNT('Ext Accident Log'[Injury Type]) / AVERAGE(EmployeeCount[Smyth Steel Employee Count]) * 100000),
DATESYTD('Calendar'[Date])
),
CALCULATE(
(COUNT('Ext Accident Log'[Injury Type]) / AVERAGE(EmployeeCount[Total Employee Count]) * 100000),
DATESYTD('Calendar'[Date])
)
)
)
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hard to say without any idea what your data looks like, but I'd probably start by checking that the average employee count is what you expect.
 
Upvote 0
Hard to say without any idea what your data looks like, but I'd probably start by checking that the average employee count is what you expect.
thanks Rory, when I take the last if out as a separate measure I get the correct value but for some reason when its in the combined If it gives me the correct value so I know the Averages are right.
 

Attachments

  • Screenshot 2024-03-06 083448.png
    Screenshot 2024-03-06 083448.png
    6.4 KB · Views: 3
Upvote 0
Ah, if you have no filter on Company, then you're actually getting the second calculation done (since Smyth Steel is 'larger' alphabetically than the other item), not the third. You probably need to nest the whole lot in something like:

IF(HASONEVALUE('Company'[Company]),do company specific bits here, do global calc here)
 
Upvote 0
thank you I had to put the global calc into the if statement twice as the 'false' part but it is now working thank you.

=IF(
HASONEVALUE('Company'[Company]),
IF(
MAX('Company'[Company]) = "Maine Group",
CALCULATE(
(COUNT('Ext Accident Log'[Injury Type]) / AVERAGE(EmployeeCount[Maine Employee Count]) * 100000),
DATESYTD('Calendar'[Date])
),
IF(
MAX('Company'[Company]) = "Smyth Steel",
CALCULATE(
(COUNT('Ext Accident Log'[Injury Type]) / AVERAGE(EmployeeCount[Smyth Steel Employee Count]) * 100000),
DATESYTD('Calendar'[Date])
),
CALCULATE(
(COUNT('Ext Accident Log'[Injury Type]) / AVERAGE(EmployeeCount[Total Employee Count]) * 100000),
DATESYTD('Calendar'[Date])
)
)
),
CALCULATE(
(COUNT('Ext Accident Log'[Injury Type]) / AVERAGE(EmployeeCount[Total Employee Count]) * 100000),
DATESYTD('Calendar'[Date])
)
)
 
Upvote 0

Forum statistics

Threads
1,215,077
Messages
6,122,991
Members
449,094
Latest member
masterms

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top