10 Replies Latest reply: Sep 16, 2016 4:45 AM by Timo Schrama RSS

    How to compare two dimensions with aggr function

    Timo Schrama

      Hi there,

       

      I need some help..

      I’ve got an database, where appointments of several types are made on multiple locations.

      Each appointment type can require different type of rooms (even multiple rooms)

      Each location has several rooms of each type.

       

      So kind of like this (oversimplified):

      AppointmentsTable:

      -AppID

      -AppTypeID

      -LocationID

       

      RoomType:

      -RoomTypeID

      -AppTypeID

       

      Location:

      -LocationID

      -RoomTypeID

      -CapacityOfRoomType

       

      Now: If I load this in QV, I get a circular reference of course. So, I’ve renamed the ID of RoomType to RoomTypeID2 – which worked obviously.

       

      But the problem is I can’t get the query right where I want to show the used Rooms vs the capacity.

      I want to show:

       

      RoomTypeID – Count(Appointments) – Count(Capacity)

      A1 – 45 – 100

      A2 – 50 – 102

       

      And now I don’t know to solve it. Any help?

      I’ve tried a aggr function like

       

      SUM(aggr(SUM([CapacityOfRoomType]),[RoomType Id], [RoomType2Id])). But it doesn’t work.

       

      I get:

      RoomTypeID2 – Count(Appointments) – Count(Capacity)

      A1 – 45 – 202

      A2 – 50 – 202

       

      If I include RoomTypeID then it shows all the correct values, So I should be close…

      RoomType2ID – RoomTypeID - Count(Appointments) – Count(Capacity)

      A1 – A1 – 45 – 100

      A1 – A2 – 0 – 102

      A2 – A1 – 50 – 100

      A2 – A2 – 0 – 102

       

      I tried something like:

      SUM(${<[RoomType2Id]]=[RoomType Id]>}aggr(SUM(${<[RoomType2 Id]]=[RoomType Id]>}[CapacityOfRoomType]),[RoomType Id], [RoomType2Id])). But it doesn’t work.

       

      I hope someone can help me by:

      1. a) Solving the circular reference by adjusting my data-model
      2. b) Correct the function or replace it somehow.

       

      Thanks!