Forum Discussion
Total WTD with USERELATIONSHIP
Hi guys, i've written the below bit of DAX but i'm getting a zero return for it - when i'm expecting a count of hundreds.
I'm assuming its because the relationship between my tables is based on the ReceivedDate rather than the ClosedDate, so i'm assuming there's an error in my code somewhere?
Any help at all would be appreciated on this one;
Closed WTD =
IF (
HASONEVALUE ( Dim_Date[Year] )
&& HASONEVALUE ( Dim_Date[WeekOfYear] ),
CALCULATE (
COUNT ( 'SysAid Extract'[ClosedDate] ),
USERELATIONSHIP ( 'SysAid Extract'[ClosedDate], Dim_Date[Date] ),
FILTER (
ALL ( Dim_Date ),
Dim_Date[Year]
= VALUES ( Dim_Date[Year] )
&& Dim_Date[WeekOfYear]
= VALUES ( Dim_Date[WeekOfYear] )
&& Dim_Date[Date]
<= MAX ( Dim_Date[Date] )
)
),
BLANK ()
) + 0
Thanks in advance, all!
OK, here is what I *think* you were going for perhaps? Hard to tell, maybe explain what the purpose of the measure, is it only supposed to count the items closed in the current week or in all weeks previous to the current week? Not sure what you were doing with the VALUES but you can't use them like that because they return a table of multiple values. I also commented out the HASONEVALUE checks because I'm not sure what you were doing with that either.
Closed WTD = //IF ( // HASONEVALUE ( Dim_Date[Year] ) // && HASONEVALUE ( Dim_Date[WeekOfYear] ), VAR __Date = TODAY() VAR __Year = YEAR(__Date) VAR __WeekOfYear = WEEKNUM(__Date) RETURN CALCULATE ( COUNT ( 'SysAid Extract'[ClosedDate] ), USERELATIONSHIP ( 'SysAid Extract'[ClosedDate], Dim_Date[Date] ), FILTER ( ALL ( Dim_Date ), Dim_Date[Year] = __Year && Dim_Date[WeekOfYear] = __WeekOfYear && Dim_Date[Date] <= __Date ) ) // ), // BLANK () //) + 0
20 Replies
- Greg_DecklerCommunity Champion
Tough to say without something to test with. 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
But I'd be willing to bet that your USERELATIONSHIP is in the wrong place?
- javirmerinoHelper III
Thanks, Greg_Deckler. Do you mind if i PM you my .pbix file to look into further, briefly?
i'd already tried putting the USERELATIONSHIP in pretty much every other part of the query. This was the only place that didnt give me a syntax error!
- Greg_DecklerCommunity Champion
Sure.
- Pragati11Super User
Hi javirmerino ,
Yes your USERRELATIONSHIP function is wrong as your relationship is based on RECEIVEDDATE.
For more details on user reltionship function refer this:
https://docs.microsoft.com/en-us/dax/userelationship-function-dax
Thanks,
Pragati
- javirmerinoHelper III
Hi Pragati11 , thanks for the feedback. However i do have a second inactive relationship between the dimensions table and the ClosedDate, which is why i'm trying to reference this also. See relationship diagram below.
Is this not the correct use for it?
- Pragati11Super User
Hi javirmerino ,
You need to have Primary relationships between the columns, in order to use USERRELATIONSHIP function.
Thanks,
Pragati