Pivot Table Measure To Calculate Items Between Range Returning Wrong Result

KrisW77

New Member
Joined
Feb 1, 2014
Messages
36
I have had my first attempt at creating a Measure for a Pivot Table to solve a problem, but I am not getting the expected results.

I am looking to calculate the number of people in an area between 2 times (Log In & Log Out using a swipe card), including a split by company.
I've followed a post on a PowerBI site Start and end time but using either of the solutions put forward I get issues

When using
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)

The Pivot Table has some instances by Company & Time period that are incorrect, and more bizzarely, the Grand Total doesnt add up.
I havent found a way to drill down or evaluate the Measure, so I cant work out where I may of gone wrong.

An example of this is from the data below at 10am, the Measure returns 8no rather than 7no (red text)
CompanyIN Swipe (Group)OUT Swipe (Group)
Company A
06:00​
18:00​
Company A
06:30​
16:00​
Company A
06:30​
16:00​
Company A
06:30​
16:30​
Company A
06:30​
16:30​
Company A
07:00​
15:30​
Company A
08:00​
09:30​
Company A
08:00​
13:00​
Company A
11:30​
11:30​

The second solution gives the correct Grand Totals for each Time period, but wont split by Company (I just get the overall total)
Code:
Number On Site 2
=
VAR vMinVal = MIN(tbl_TimeGroup[Value])
VAR vMaxVal = MAX(tbl_TimeGroup[Value])
VAR vNumberOnSite = COUNTROWS( FILTER( ALLSELECTED(tbl_SiteEntryExit), tbl_SiteEntryExit[] <= vMinVal && tbl_SiteEntryExit[] >= vMaxVal))
RETURN
vNumberOnSite

Can anyone advise where I may of gone wrong?
And/ Or any good resources to start learning the basics??

Thanks

Kris
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,224,910
Messages
6,181,676
Members
453,061
Latest member
schiefA

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