Pivot Table Measure To Calculate Items Between Range Returning Wrong Result

KrisW77

New Member
Joined
Feb 1, 2014
Messages
36
While I have already asked this question under the Power BI Tools section, it appears that part of the site gets less visits, my frustration has continued and I am trying to understand the mechanics of the COUNTIFS function, as I can replicate the issue with normal Excel formula if i break it down into steps. So if i can find the solution in normal Excel, perhaps I can figure out the solution in Power Pivot.
My original post is Pivot Table Measure To Calculate Items Between Range Returning Wrong Result

Using the example data (with just 1 company)
MrExcel - Data Set.JPG

Then using the Measure
Code:
Number On Site
=
VAR vMinVal = MIN(tbl_TimeGroup[Value])
VAR vMaxVal = MAX(tbl_TimeGroup[Value])
VAR vSiteEntry = CALCULATE( COUNTROWS(tbl_SiteEntryExit), tbl_TimeGroup[Value] <= vMinVal, ALL(tbl_TimeGroup))
VAR vSiteExit = CALCULATE( COUNTROWS(tbl_SiteEntryExit), tbl_TimeGroup[Value] >= vMaxVal, ALL(tbl_TimeGroup), USERELATIONSHIP(tbl_SiteEntryExit[OUT Swipe (Group)], tbl_TimeGroup[Value]))
RETURN
MIN(vSiteExit, vSiteEntry)
results in the Pivot Table below. To the right hand side are the results using CountIfs(), which are what the answer should be (and is checked against filtering the data for each 30min period).
The yellow highlights the difference.
MrExcel - Pivot v CountIfs.JPG


If I break the CountIfs down into SiteEntry & SiteExit and then Min(SiteEntry, SiteExit), similar to the Measure, I replicate the Pivot Table result.
MrExcel - CountIfs Breakdown.JPG


Can anyone advise how I can achieve the desired result without using the normal CountIfs solution??

While only testing on a small subset of data, this will be used daily on a large data set, and I need to find an easy and robust solution that anyone can use by just adding the data into the spreadsheet.

regards

Kris
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,215,045
Messages
6,122,840
Members
449,096
Latest member
Erald

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