Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
godinbl
Frequent Visitor

Trying to establish relationship between values in 2 tables where 1 value is IN the other in PowerBi

I have 2 tables:  MeterReadings and Auths and a common field called auth

 

The MeterReadings data looks like this:

 

meterrefclientrefclientnamewmaauthreaddatereading
20476233141JAMES LINDSAY ROBINSONBurdekin Groundwater Management Area1006581/08/20240.063
20476233141JAMES LINDSAY ROBINSONBurdekin Groundwater Management Area1006581/08/20240.058
17408233141JAMES LINDSAY ROBINSONBurdekin Groundwater Management Area10065831/07/202464.809
17408233141JAMES LINDSAY ROBINSONBurdekin Groundwater Management Area10065816/06/202464.525
8572177132CATHERINE AGNES QUAGLIATA; LEO CHARLES ANDREW QUAGLIATABurdekin Groundwater Management Area 103387; 61866422/07/20226,389.93
8572177132CATHERINE AGNES QUAGLIATA; LEO CHARLES ANDREW QUAGLIATABurdekin Groundwater Management Area 103387; 61866413/06/20236,446.00
8572177132CATHERINE AGNES QUAGLIATA; LEO CHARLES ANDREW QUAGLIATABurdekin Groundwater Management Area103387; 61866410/06/20246,664.04
8971238641MARINA ANN MARSON; MICHAEL MARSONBurdekin Groundwater Management Area 17441330/06/20231,120.92
8971238641MARINA ANN MARSON; MICHAEL MARSONBurdekin Groundwater Management Area 17441328/06/20221,051.00
8971238641MARINA ANN MARSON; MICHAEL MARSONBurdekin Groundwater Management Area1744138/06/20241,249.10
15175172163ENRICO MIO; PAOLO MIO; MARIO MIOBurdekin Groundwater Management Area 175218; 62139025/07/2023911.281
15175172163ENRICO MIO; PAOLO MIO; MARIO MIOBurdekin Groundwater Management Area 175218; 6213904/07/2022895.487
15175172163ENRICO MIO; PAOLO MIO; MARIO MIOBurdekin Groundwater Management Area175218; 6213903/09/2024912.221
17400249245AUSTRALIAN CANE FARMS LIMITEDBurdekin Groundwater Management Area 175827; 6157623/07/20236,231.29
17400249245AUSTRALIAN CANE FARMS LIMITEDBurdekin Groundwater Management Area 175827; 61576220/06/20225,829.51
17400249245AUSTRALIAN CANE FARMS LIMITEDBurdekin Groundwater Management Area175827; 61576210/06/20246,622.37
17400249245AUSTRALIAN CANE FARMS LIMITEDBurdekin Groundwater Management Area175827; 61576212/02/20246,435.58
17400249245AUSTRALIAN CANE FARMS LIMITEDBurdekin Groundwater Management Area175827; 61576212/02/20246,435.54
15097241129JOSEPH LEON CALTABIANO; ROSA CALTABIANO; SALVATORE ALFIO NATALE CALTABIANOBurdekin Groundwater Management Area 176441; 61866830/06/2022878.924

 

notice that the auth field can have 1 auth or many auths - I am trying to create a relationship between my 2 tables where the auth value in the Auths table is IN the auth field in the MeterReadings table

 

my table in PowerBi looks like this:

godinbl_0-1731473418029.png

and you can see that when there are multiple auths it cannot calculate the value for Entitlement

 

This my code for the Entitlement field in the table:

 

Entitlement = 
VAR _auth = [Auth--auth]
VAR _zone = [Zone]
VAR _vol =
    CALCULATE (
        SUM ( 'Auths'[volumeML] ),
        'MeterReadings'[auth] = _auth )

VAR _amo =
    CALCULATE (
        SUM ( 'SWANs'[amount] ),
        'SWANs'[authorisation] = _auth,
        'SWANs'[expirydate] >= MIN ( 'MeterReadings'[readdate] ),
        'SWANs'[expirydate] <= MAX ( 'MeterReadings'[readdate] )
    )
VAR _thisyear =
    CALCULATE ( SUM ( 'AEs'[thisyear] ), 'AEs'[subcatchment] = _zone )
VAR _sumsd_pa =
    CALCULATE (
        SUM ( 'Auths'[SandDValue] ) + SUM ( 'Auths'[PAValue] ),
        'Auths'[Auth--auth] = _auth
    )
RETURN
    ( _vol + _amo ) * _thisyear + _sumsd_pa

 

 

this is not bringing up any errors but obviously this part of the code needs to be changed to account for multiple auths:

VAR _vol =
    CALCULATE (
        SUM ( 'Auths'[volumeML] ),
        'MeterReadings'[auth] = _auth )
 
I have already split the auth field in the Auths table so it contains single auths
any assistance with this much appreciated
1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Your meterreadings table is missing a primary key, something that can uniquely identify each reading.

 

Then you are missing an auth dimension table

 

And finally you are missing the mapping table between reading IDs and auth values.

 

See attached for a solution proposal.

 

lbendlin_0-1731490738208.png

 

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

Your meterreadings table is missing a primary key, something that can uniquely identify each reading.

 

Then you are missing an auth dimension table

 

And finally you are missing the mapping table between reading IDs and auth values.

 

See attached for a solution proposal.

 

lbendlin_0-1731490738208.png

 

@lbendlin thanks for your response - my question to you was ambiguous and your answer therefore not a solution in itself but you mentioned primary keys and IDs mapping to each table and that was my problem - everything working now - THANK YOU!

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.