Forum Discussion

RavitPBI's avatar
RavitPBI
Frequent Visitor
5 years ago
Solved

Calculation using different tables with no relationship

Table A: Outbound

Date_idOrg_idOutboundUnits
180500.00
280600.00
380700.00
186100.00
286200.00
386300.00

 

Table B: Inbound

Date_idOrg_idVendor_idInboundUnits
180150.00
180260.00
280170.00
280210.00
380120.00
380230.00
186150.00
186260.00
286170.00
286210.00
386120.00
386230.00

 

Table C: GoalUPH (Goal Units per Hour)

Date_idOrg_idGoalUPH
18020.00
28020.00
38020.00
18625.00
28625.00
38625.00

 

My data model has the above setup of tables A, B and C (amongst many other tables). Unfortunately, there is no active/inactive relationship between these A, B, C tables (since my PowerBI desktop doesn't allow for many-to-many relationships). I am trying to achieve the following formula:

HoursNeeded = (OutboundUnits + InboundUnits) / GoalUPH --> for each combination of Date_id and Org_id.

 

So, for example, for Date_id = 1 and Org_id = 80, the calculation would (mathematically) go like:

HoursNeeded = (500.00 + (50.00 + 60.00)) / 20.00 = 30.5

 

I'd appreciate any help in creating the above calculation. Thanks!

  • Hi, RavitPBI 

     

    It’s my pleasure to answer for you.

    According to your description, I think you can create two slicers(column in table C) and a measure to calculate the desired result.

    Like this:

    HoursNeeded =
    VAR dateid =
        SELECTEDVALUE ( GoalUPH[Date_id] )
    VAR orgid =
        SELECTEDVALUE ( GoalUPH[Org_id] )
    VAR sumunits =
        SUMX (
            FILTER ( ALL ( Outbound ), [Date_id] = dateid && [Org_id] = orgid ),
            [OutboundUnits]
        )
            + SUMX (
                FILTER ( ALL ( Inbound ), [Date_id] = dateid && [Org_id] = orgid ),
                [InboundUnits]
            )
    RETURN
        IF (
            ISFILTERED ( GoalUPH[Date_id] ) && ISFILTERED ( GoalUPH[Org_id] ),
            DIVIDE ( sumunits, SELECTEDVALUE ( GoalUPH[GoalUPH] ) ),
            0
        )

    If it doesn’t solve your problem, please feel free to ask me.

     

    Best Regards

    Janey Guo

     

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

4 Replies

    • RavitPBI's avatar
      RavitPBI
      Frequent Visitor

      Hi amitchandak,

       

      Thanks for providing the right direction. The video gave some ideas to build upon my own solution using bridge tables. Appreciate the help a lot! 🙂 

  • v-janeyg-msft's avatar
    v-janeyg-msft
    Icon for Community Support rankCommunity Support

    Hi, RavitPBI 

     

    It’s my pleasure to answer for you.

    According to your description, I think you can create two slicers(column in table C) and a measure to calculate the desired result.

    Like this:

    HoursNeeded =
    VAR dateid =
        SELECTEDVALUE ( GoalUPH[Date_id] )
    VAR orgid =
        SELECTEDVALUE ( GoalUPH[Org_id] )
    VAR sumunits =
        SUMX (
            FILTER ( ALL ( Outbound ), [Date_id] = dateid && [Org_id] = orgid ),
            [OutboundUnits]
        )
            + SUMX (
                FILTER ( ALL ( Inbound ), [Date_id] = dateid && [Org_id] = orgid ),
                [InboundUnits]
            )
    RETURN
        IF (
            ISFILTERED ( GoalUPH[Date_id] ) && ISFILTERED ( GoalUPH[Org_id] ),
            DIVIDE ( sumunits, SELECTEDVALUE ( GoalUPH[GoalUPH] ) ),
            0
        )

    If it doesn’t solve your problem, please feel free to ask me.

     

    Best Regards

    Janey Guo

     

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

    • RavitPBI's avatar
      RavitPBI
      Frequent Visitor

      Hi v-janeyg-msft,

       

      Thanks for sharing the solution. While it seems this calculation would work with your recommendation, however, usage of slicer is not an option for me. This calculation should be performed behind the scenes without the use of any end-user interaction. Appreciate the help!