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

USERELATIONSHIP in a filtered measure

I need to create a measure that calculates daily goals over time based on the number of active employess. I have an inactive relationship between 'Employees'[StartDate] and 'Date'[Date]. I have tried using the following:

 

Daily_Goal = 

VAR EmpCount = CALCULATE(COUNTROWS('Employees'),

                                                 'Employees'[StartDate]<='Date'[Date],

                                                  USERELATIONSHIP( 'Employees'[StartDate], 'Date'[Date]))

RETURN

20 * EmpCount

 

But I receive an error that "the expression contains multiple columns, but only a single column can be used in a True/False expression that is used as a table filter expression."

 

Is there a way to calculate this goal using an inactive relationship? I am unable to make this relationship active as I have a different table with an active relationship that links between the 'Date' table and the 'Employees' table.

 

1 ACCEPTED SOLUTION

@Anonymous seems like I'm missing something here. seems like you are looking running total

 

Daily_Goal = 
VAR EmpCount = 
CALCULATE(COUNTROWS('Employees'),
USERELATIONSHIP( 'Employees'[StartDate], 'Date'[Date]))
FILTER( ALL(Date ),
Date[Date] <= MAX( Date[Date]
),
RETURN
20 * EmpCount


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

7 REPLIES 7
parry2k
Super User
Super User

@Anonymous hmm not full sure but try following:

 

 
Daily_Goal = 
VAR EmpCount = CALCULATE(COUNTROWS('Employees'),
FILTER( Employees,
                                                 'Employees'[StartDate]<='Date'[Date]
),
                                                  USERELATIONSHIP( 'Employees'[StartDate], 'Date'[Date]))
RETURN
20 * EmpCount


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

@parry2k  thank you but unfortunately this solution gives an error message that "A single value for column 'Date' in table 'Date' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result."

@Anonymous sorry, change Date[Date] to MAX( Date[Date] )



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Adding MAX does get rid of the error but only calculates for the dates linked between the two tables

 

For example, the following in the Employee Table

Employee      StartDate

Employee1    1/2/2019 

Employee2    1/2/2019

Employee3    1/5/2019

 

The measure returns the following if I drop it in a table with continuous dates

Date                 Daily_Goal

1/2/2019          40

1/3/2019          NULL

1/4/2019          NULL

1/5/2019          20

 

The output I am looking for is

Date                 Daily_Goal

1/2/2019          40

1/3/2019          40

1/4/2019          40

1/5/2019          60

@Anonymous seems like I'm missing something here. seems like you are looking running total

 

Daily_Goal = 
VAR EmpCount = 
CALCULATE(COUNTROWS('Employees'),
USERELATIONSHIP( 'Employees'[StartDate], 'Date'[Date]))
FILTER( ALL(Date ),
Date[Date] <= MAX( Date[Date]
),
RETURN
20 * EmpCount


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

but your solution has synta errors !!!

Anonymous
Not applicable

@parry2k That's it!! Thank you!!

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.

Top Solution Authors