Forum Discussion
Countax with selectedvalue expresion returns Zero
Hi
I started with this thread wondering how to solve the issue. From there I got to a solution with a DAX meassure but it's not working for the totals.
I got this table:
| Actor | Time Start | Time End | Date | Total hours | Content type | ID |
| A | 10:00 | 12:00 | 01/01/2021 | 2.00 | A | A01/01/202110:0012:00 |
| B | 08:00 | 12:00 | 02/01/2021 | 4.00 | B | B02/01/20218:0012:00 |
| A | 10:00 | 12:00 | 03/01/2021 | 2.00 | A | A03/01/202110:0012:00 |
| A | 12:00 | 14:00 | 03/01/2021 | 2.00 | AB | AB03/01/202112:0014:00 |
| A | 10:00 | 12:00 | 04/01/2021 | 2.00 | AB | AB04/01/202110:0012:00 |
| B | 10:00 | 12:00 | 04/01/2021 | 2.00 | AB | AB04/01/202110:0012:00 |
| A | 09:00 | 13:00 | 05/01/2021 | 4.00 | AB | AB05/01/20219:0013:00 |
| B | 16:00 | 18:00 | 05/01/2021 | 2.00 | AB | AB05/01/202116:0018:00 |
It records whos is recording in a studio (Actor) and what is recording (content type).
They can record content only for them (A or B) or content for both (AB).
The content for both (AB) can be recorded separately or together (same time and date)
The problem is when they record together, the recording session adds the double of time. i.e. the session of the 04/01/2021 A and B are recording together in a 2 hours session length, but the sum will acount it as 4 hours of recording.
My approach is concatenat the ID column = [Content type] & [Date] & [time start] & [time end]
This ID will be repeated by the people recording togehter (same time and date), therefore I wrote this Measure:
both adjst = SUMX ( Data, Data[Total hours] / COUNTAX ( Data, SELECTEDVALUE ( Data[ID] ) ) )
It works as expected
Just the date 04/01/2021 is summirezed and divided by the count of IDs... the problem is that I need the total as well.
I understand the the total returns infinity because theres no selectedvalue and returns Zero, so the division is infinity, but I don't know other way to do this. It could work as well in a DAX added column but thhis way selectedvalue won't work.
I tried using and IF:
both adjst 2 =
IF (
ISBLANK ( SELECTEDVALUE ( Data[ID] ) ),
SUMX ( Data, Data[Total hours] / COUNTA ( Data[ID] ) ),
SUMX ( Data, Data[Total hours] / COUNTAX ( Data, SELECTEDVALUE ( Data[ID] ) ) )
)
but this doesn't work for the total
I tried CALCULATE and the expresion above with an filtering thinking it would be executed row by row...but the result is the same.
I'm thinking a dax column would do the work but no clue how to do it. A new column with the fixed values for Total hours, meaning Total hours divided by the count of The ID appear in the table.
Any idea will be welcome 🙂
thanks
Pepe
- Anonymous5 years ago
Hello Anonymous
Create a calculated column using the below calculation.Hour =VAR TotalID =CALCULATE ( COUNT ( Recordings[ID] ), ALLEXCEPT ( Recordings, Recordings[ID] ) )RETURNDIVIDE ( [TotalHours], TotalID )
9 Replies
- AnonymousNot applicable
Hello Anonymous
As you've mentioned the A and B are recording so the hours will the sum (4 hours), but in the count of ID = 2, I can see only 2 hours.
Are you looking for something like the below image?- AnonymousNot applicable
Hi Anonymous
No, the total is not 20, it should be 18. Because the hours at 4/01/21 are 2 not 4.
My measure is working at a row level, but not for the total that returns infinity, thats my problem.
Thanks!!
- AnonymousNot applicable
Hello Anonymous
Instead of measure try a calculated column and plot into the table.
- wdx223_Daniel
Community Champion
- AnonymousNot applicable
Ohhh that was something I though about but didn't try how to do it. I'm gonna implement that in my report but I think that's going to work 🙂
Thanks!!
- AnonymousNot applicable
It works well a solves the problem!!!
Cheers!!