Forum Discussion

ThomasWeppler's avatar
ThomasWeppler
Impactful Individual
4 years ago
Solved

Filter and userelationship in same DAX

Hi powerBI community

I want to use a filter and the userelationship function in the same meassure.
I have tried this and it doesn't work:

Rollout =
Var network_ = {19,20,21,22,43,44}
Return
CALCULATE (COUNT ( 'Projects'[id] ),
USERELATIONSHIP(Calender[Date], Projects[Deadline]),
FILTER(Projects, Projects[Projecttype] IN network_),
FILTER(Projects, Projects[C HP-Status] = "HP DONE"))


However no results are shown
I have tried only to use a filter or the userelationship function and that works perfecktly fine
This works:

Rollout =
CALCULATE (COUNT ( 'Projects'[id] ),
USERELATIONSHIP(Calender[Date], Projects[Deadline])

And this also works: 
Rollout =
Var network_ = {19,20,21,22,43,44}
Return
CALCULATE (COUNT ( 'Projects'[id] ),
FILTER(Projects, Projects[Projecttype] IN network_),
FILTER(Projects, Projects[C HP-Status] = "HP DONE"))

 

So I know that the problem is how I combine the filter and the userelationship function.

Any help would be greatly appreciated.

9 Replies

  • ThomasWeppler it should work, how you are visualizing the data:

     

    Rollout =
    Var network_ = {19,20,21,22,43,44}
    Return
    CALCULATE (COUNT ( 'Projects'[id] ),
    USERELATIONSHIP(Calender[Date], Projects[Deadline]),
    Projects[Projecttype] IN network_,
    Projects[C HP-Status] = "HP DONE")

     

    Follow us on LinkedIn

     

    Learn about conditional formatting at Microsoft Reactor

    My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

     

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

    • ThomasWeppler's avatar
      ThomasWeppler
      Impactful Individual

      In a grouped bar chart.
      In my axis I have year, quarter, month, week and day which allows drill down.

    • ThomasWeppler's avatar
      ThomasWeppler
      Impactful Individual

      I think it will be hard to know if I have removed all the sensative data.
      Especially on a forum full of Power BI experts, someone might be able to get some info back I was supposed to deleted. So I don't want to share the pbix file.

  • You could resolve with two calculate like this

     

    CALCULATE (CALCULATE(COUNT ( 'Projects'[id] ), USERELATIONSHIP(Calender[Date]Projects[Deadline]), (ProjectsProjects[C HP-Status] = "HP DONE"))

  • ThomasWeppler's avatar
    ThomasWeppler
    Impactful Individual

    So in the end I just used the Userelationship and added the filters in the filter colon and made them hidden so they won't distract the end user.
    It works which is awesome, but it means that I will have to add the extra filters on each visualization so it is not as elegant a solution as I would have hoped for. But I think it will have to do for now.

  • Hi, ThomasWeppler 

    May I ask if your problem has been solved? Is the above post helpful to you?

    If  it does, could you please mark the post which help as Answered? It will help the others in the community find the solution easily if they face the same problem with you. Thank you.

     

     

    Best Regards,
    Community Support Team _ Zeon Zheng

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • VIPER129MMG's avatar
    VIPER129MMG
    Frequent Visitor
    Alguém consegue me ajudar na função abaixo, ao digitar o resultado é branco
     
    BACKLOG =
    VAR BACKLOG = "VIEW_ORDERS_BACKLOG."

    RETURN
    CALCULATE([PEDIDOS],
    USERELATIONSHIP(dCALENDARIO[DATA],fPEDIDOS[C6_ENTREG]),
    FILTER(fPEDIDOS, fPEDIDOS[ORIGEM] IN {BACKLOG}))