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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jday
Helper I
Helper I

max of two different tables with the same columns that are in a 1:* relationship

I am looking for a way to take the max of a column that is in two different tables.  

The data looks something like this 

 

table 1

x      y    z     

1     2     2

2     2     2

3     3     3 

4     4     4

5     5     5

 

 

table 2

x     y     z

1    4     4

1    2     4

2    1     1 

3    6     6

3    4     6

3    4     6

4    1     1

5    4     4

 

 

Desired Results 

x          z     

1          4

2          2

3          6

4          4

5          5


If there are any other ways to solve this problem I am open to changing my approach.  The end goal is to have a dashboard that will take the max after slicing away results from Y.  

 

 

 

 

6 REPLIES 6
v-ljerr-msft
Employee
Employee

Hi @jday,

 

Based on my test, you should be able to use the formula below to create a new calculate column in table1 to get the max value of z from both table1 and table2.Smiley Happy

 

maxZ =
IF (
    Table1[z] >= CALCULATE ( MAX ( Table2[z] ), RELATEDTABLE ( Table2 ) ),
    Table1[z],
    CALCULATE ( MAX ( Table2[z] ), RELATEDTABLE ( Table2 ) )
)

maxZ.PNG

 

Regards

Hey @v-ljerr-msft,

 

This is really close to what I need.  I forgot to post this, but I need a slicer to apply to these tables before they calculate a max.  With what you provided it is currently taking the max of the two z columns (which is what I need).  I need Y to be able to act as a slicer though.  

Hi @jday,

 

Try using the formula below to create a new measure, then show the measure with Table1[x], Table1[y] column on a Table visual. It should work in your scenario.Smiley Happy

 

maxZ = 
IF (
    MAX ( Table1[z] ) >= CALCULATE ( MAX ( Table2[z] ), RELATEDTABLE ( Table2 ) ),
    MAX ( Table1[z] ),
    CALCULATE ( MAX ( Table2[z] ), RELATEDTABLE ( Table2 ) )
)

r1.PNG

 

Regards

Hey @v-ljerr-msft,

 

I created 2 fake datasets so I could show you what I was wanting.  Currently when I use this solution I get everyone who falls into that category.  

 

What I want is to select the max of x that would be applied after slicing on a variable. 

 

The data I created is below.  I will also show what my desired results are. 

 

Table 2

xyz
1Green3
2Blue2
3Red6
4Yellow4
5Orange5
6Orange5
7Red6
8Black1
9Black1
10Yellow4

   

Table 1

xyz
1red6
1blue2
1red6
1red6
1blue2
1blue2
1yellow4
2green3
2green3
2red6
2blue2
3yellow4
3orange5
3black1
3red6
3red6
3blue2
4red6
4yellow4
5green3
6yellow4
6red6
6red6
7orange5
8red6
8red6
8red6
8red6
8red6
8red6
8red6
8yellow4
8orange5
8green3
8green3
8green3
8green3
9green3
9green3
9orange5
9orange5
10red6

 

Max of every x member. 

 

xred orange yellow greenblueblack
1604321
2600321
3600021
4604001
5050301
6654001
7650001
8654301
9050321
10604001

 

 

 

powerBiHelp.PNG

 

These results are displaying the max as 6 for every value in x.  

 

The desired results would actually be something like this. 

 

Lets assume everyone falls into 'black' as a default if they do not have a max of something else. 

 

  filter
zcount distinct  of xy = everything but red
10 
21 
31 
43 
55 
60 
   
  filter
zcount distinct  of xy = Everything but red and orange
11 
21 
33 
45 
50 
60 
   
  filter
zcount distinct  of xy = only blue and black 
16 
24 
30 
40 
50 
60 

 

Please let me know if I can provide anything else that would be of help.  

 

 

 

 

@v-ljerr-msft,

 

Your solution will work if I could filter the data before the max was taken.  Do you know if this would be possible?  

Hi @jday,

 

Could you try the formula below to see if it works in your scenario? Smiley Happy

 

maxZ =
VAR selectedY =
    FIRSTNONBLANK ( Table1[y], 1 )
RETURN
    IF (
        MAX ( Table1[z] )
            >= CALCULATE (
                MAX ( Table2[z] ),
                FILTER ( RELATEDTABLE ( Table2 ), Table2[y] = selectedY )
            ),
        MAX ( Table1[z] ),
        CALCULATE (
            MAX ( Table2[z] ),
            FILTER ( RELATEDTABLE ( Table2 ), Table2[y] = selectedY )
        )
    )

 

Regards

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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