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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
decarsul
Helper V
Helper V

Returning value from inactive related table

Good day all,

 

Today i'm trying to eventually create a measure to show a sum of a value in a bar or line chart, where the value is only show once, based on the max of phase.

To do this, i need data from 2 tables. I cannot use calculated columns, because of using DirectQuery, so it has to be done in a measure. Table1 is a Facts table, Table2 is a Dimension table. Below an abbreviation of the tables.

 

Table 1   
IDPhaseetc.etc.
11  
12  
13  
21  
31  
32  
41  
51  
52  
53  

 

Table 2  
IDAmountetc.
120 
231 
3647 
4684 
5645 
654897 
75646312 
86846 
9465486 
1058 

 

There is no active direct relationship between the 2 columns. There is however an in-active relation between the 2, based on ID column.

 

Now the question is. How will i get a table / measure that will show Table 1, but only the MAX of Phase. Like:

Table result  
IDPhaseAmountetc
1320 
2131 
32647 
41684 
53645 

 

Eventually i want to have a bar chart. Where a Sum of Amount if shown as value, and Phase is shown on the X axis. So in this example, that would mean Phase 1 shows 710, Phase 2 shows 647 and Phase 3 shows 665.

 

I have tried using Summarize
SUMMARIZE(
Table1,
Table2[ID],
"temp1",
MAX(Table1[amount]))

and lookupvalue. (with and without userelationship)
CALCULATE(
LOOKUPVALUE(
Table2[Amount],
Table1[Phase], MAX(Table1[Phase]),
Table2[ID],VALUES(Table2[ID]])
), USERELATIONSHIP(table1,table2))

 

Would love to hear your thoughts!

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

@decarsul 
Here is the updated sample file https://we.tl/t-sttvJNdSEV

1.png

Amount Measure = 
VAR T1 =
    SUMMARIZE ( 'Table 1', 'Table 1'[ID], 'Table 1'[Phase] )
VAR T2 =
    ADDCOLUMNS (
        T1,
        "@MaxPhase", CALCULATE ( MAX ( 'Table 1'[Phase] ), ALLEXCEPT ( 'Table 1','Table 1'[ID] ) ),
        "@Amount", 
            CALCULATE (
                SUM ( 'Table 2'[Amount] ),
                USERELATIONSHIP ( 'Table 2'[ID], 'Table 1'[ID] ),
                CROSSFILTER ( 'Table 2'[ID], 'Table 1'[ID], BOTH )
            )
    )
VAR T3 = 
    FILTER ( T2, [Phase] = [@MaxPhase] )
RETURN
    SUMX ( T3, [@Amount] )

View solution in original post

8 REPLIES 8
tamerj1
Super User
Super User

@decarsul 
Here is the updated sample file https://we.tl/t-sttvJNdSEV

1.png

Amount Measure = 
VAR T1 =
    SUMMARIZE ( 'Table 1', 'Table 1'[ID], 'Table 1'[Phase] )
VAR T2 =
    ADDCOLUMNS (
        T1,
        "@MaxPhase", CALCULATE ( MAX ( 'Table 1'[Phase] ), ALLEXCEPT ( 'Table 1','Table 1'[ID] ) ),
        "@Amount", 
            CALCULATE (
                SUM ( 'Table 2'[Amount] ),
                USERELATIONSHIP ( 'Table 2'[ID], 'Table 1'[ID] ),
                CROSSFILTER ( 'Table 2'[ID], 'Table 1'[ID], BOTH )
            )
    )
VAR T3 = 
    FILTER ( T2, [Phase] = [@MaxPhase] )
RETURN
    SUMX ( T3, [@Amount] )

Seems to work again. Time to validate!

 

Validated, works as intended. 

Thanks for the help!

tamerj1
Super User
Super User

Hi @decarsul 
I don't realy undestand the need for Table 2. Here is a solutio based on Table 1 with one added calculated column https://we.tl/t-MV57LgfmCG

2.png1.png

Latest Phase = 
CALCULATE (
    MAX ( 'Table 1'[Phase] ),
    ALLEXCEPT ('Table 1', 'Table 1'[ID] )
)
Amount Measure = 
SUMX (
    VALUES ( 'Table 1'[ID] ),
    CALCULATE ( SELECTEDVALUE ( 'Table 1'[Amount] ) )
)

Table 2 has the amount, where table 1 does not. Maybe it would have been better to not include that one in the sample above. As such, ill edit and remove that particular column to reduce confusion.

And as mentioned, since i'm using DirectQuery, i cannot create calculated columns, because the PowerBI Service which we publish to, does not support that.

@decarsul 
Here you go https://we.tl/t-iaJTiS2ZNa

2.png

 

Amount Measure = 
CALCULATE (
    SUM ( 'Table 2'[Amount] ),
    USERELATIONSHIP ( 'Table 2'[ID], 'Table 1'[ID] ),
    CROSSFILTER ( 'Table 2'[ID], 'Table 1'[ID], BOTH )
)

 

Alright, that seems to work.

Wasn't aware off the crossfilter function.

 

Time for validation!

@decarsul 
Not sure about the result of the aggregation. It depends on your business logic but shall not an issue to amend.

so i just validated. It doesn't add up.

I'm missing the MAX filter on the phase level.

Right now, its counting the amount per Phase, but i only want it to count based on MAX of the Phase.

 

Simply adding an MAX filter, doesn't work.

So how am i introducing the MAX for phase nr?

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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