Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Wrong Sum totals when using DISTINCTCOUNT multiplied by measures

Hi there,

 

I have found a few posts about how people expect the row totals to be the sum of the rows but how it isn't and how it is technically correct and not a bug, still I was not able toget any of the provided solutions to work. I tried SUMX, Calculate without success.

 

Maybe I am missing something... 

 

My measures: 

WHRS = Work Schedule hrs per day per employee (calculated column)

RWD = Days where time was reported

RWD_HRS = WHRS * RWD for any given period of time, e.g. week 25

 

WHRS is a calculated Column in a Userlist table and Timelog data is ina  Timelog table. The measures reside in the timelog table.

UR = utilization rate based off the reported time divided by the 100%, i.e. work time (WHRS*RWD)

 

RWD = DISTINCTCOUNT('Timelog (ALL)'[Timelog.trackedDate])

RWD_HRS = RWD*SUM('Contact (User list)'[WHRS])

WHRS = Switch( 'Contact (User list)'[Contact.lastName],"name1",8.75,"name2",8.75,"name3",7,"name4",3.5,7.4)

is adding the work time as decimal per defined user and 7.4 hrs for all the rest in the user table.

 

UR = SUM('Timelog (ALL)'[Timelog.hours]) / RWD_HRS)

 

Measures work fine on the individual rows as pointed out by many of the posts, however the row totals are not working as expected.

 

Table totals for week 25, top line is the one that does the hrs correctly as they are part of the timelog table and not a measure. the rest are measures and only work on the individual rows.

2018-06-27 16_18_18-timelog_v1.1 - Power BI Desktop.png

RWD_HRS total for the group is shown as 362 and RWD as 7 where as if I pivot the data it will just sum the individual rows and show RWD_HRS as 259 and RWD as 35.

 

I found this post in particular that offers a very easy way out... by switching off the row totals... since the individual totals are correct... however... I need to show the sum for the groups. How?

 

EDIT: I use DISTINCTCOUNT since I only want each date of time reported once to determine if an employee has worked on that day, as there could be several entries for one date. Maybe there is a better way to determine the number of days worked per employee?

 

Any help and pointers are much appreciated. Thanks for reading!

 

Cheers,

Alexander

 

7 REPLIES 7
Greg_Deckler
Super User
Super User

Any chance you can post sample/example data? Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

The answer often involves a combination of HASONEVALUE/HASONEFILTER and ALLSELECTED. Check out my MM3TR&R Quick Measure here: 

 

https://community.powerbi.com/t5/Quick-Measures-Gallery/Matrix-Measure-Total-Triple-Threat-Rock-amp-...

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Some sample data:
-> dropbox: sample_data.xlsx

 

TeamsEmployee NameHrsRWD_HRSRWDURWeekDay
team1name17.757.41104.73%2518
team1name15.587.4175.45%2519
team1name16.57.4187.84%2520
team1name16.677.4190.09%2521
team1name16.57.4187.84%2522
team1name277.4194.59%2519
team1name26.57.4187.84%2520
team1name267.4181.08%2521
team1name26.57.4187.84%2522
team1name35.57.4174.32%2518
team1name35.57.4174.32%2519
team1name377.4194.59%2520
team1name367.4181.08%2521
team1name357.4167.57%2522
team1name357.4167.57%2523
team1name4137.41175.68%2517
team1name4107.41135.14%2518
team1name45.757.4177.70%2521
team1name45.757.4177.70%2522
team1name56.257.4184.46%2518
team1name56.587.4188.96%2519
team1name567.4181.08%2520
team1name56.57.4187.84%2521
team1name55.337.4172.07%2522
team1name62.87.4137.84%2518
team1name60.177.412.25%2519
team1name66.67.4189.19%2520
team1name62.487.4133.56%2521
team1name62.177.4129.28%2522
team1name787.41108.11%2518
team1name77.427.41100.23%2519
team1name77.927.41106.98%2520
team1name75.337.4172.07%2521
team1name73.837.4151.80%2522
team1name74.337.4158.56%2523
team2name87.57.41101.35%2518
team2name97.57.41101.35%2519
team2name97.57.41101.35%2520
team2name967.4181.08%2521
team2name957.4167.57%2522
team2name95.57178.57%2518

 

Timelog table (relation with contact list table via userid column)

2018-06-27 16_52_42-timelog_v1.1 - Power BI Desktop.png

 

In essence with DISTINCTCOUNT on the .trackedDate field I am determining the number of days an employee has worked and then multiply it with the work schedule hours associate with that employee from the userlist table.

 

Edit: adding relationship: Contact.id <--> Timelog.userId

2018-06-27 16_59_45-timelog_v1.1 - Power BI Desktop.png

 

So, I am not going to hand type a Timelog table FYI.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

^^ i was looking for a file attach button ... uploaded to dropbox now. That's an export from PowerBI from the Matrix visual.

I have the first table downloaded but not the Timelog (second table image). Am I missing a link in your post?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

My bad! I made a zip of the actual tables as the previous sample was already a combination of data from the visual.

 

sample data (dropbox) 

 

The zip contains these tables

1) Timelog

2) Contact teams

3) Contact User List

 

Relationships:

Contact Teams .memberIds *---<>---1 Contact User list .Contact.Id

Contact User List .Contact.ID 1---<>---* Timelog .userID

 

All Measures are currently created within the Timelog table in PowerBI (RWD/RWD_HRS/UR).

 

Thanks for your time! Much appreciated!

 

 

Anonymous
Not applicable

I tried a few more times without luck. I am beginning to think I might need a "helper" table where I "duplicate" the days worked info and the sum of time worked for a day there and just put the work time per day also there for each day... maybe...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.