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
newbiepowerbi
Helper II
Helper II

Values or relatedtable?

Hello,

 

I have two tables:

 

Table 1

 

Obj IDContract type
1Accrued
1Accrued
1Prepaid
2Accrued
2Accrued

 

Table 2:

 

Obj ID
1
2

 

I will create a SUMX measure in table 2, to compute for a value only if it does not contains in table 1 contract type "Prepaid". So basically it should compute for a value in Obj ID 2. 

 

So since it is a sumx function, it will iterate every row in table 2, ask if "Prepaid" in Table 1. My question is should i use Values(table1) so it will filtered should values pertaining to specific obj ID? do i need to put calculate so it can access table 1 and use the row in table 2 as a filter context? or should i use relatedtable? if yes i can select the contract type column to make my IN logic works?

1 ACCEPTED SOLUTION

Hi @newbiepowerbi 

 

I’ve been looking at how you would add a calculated column to Table 2 that will do the calculation you want. However, I’m not sure how to do this. SUMX iterates across rows but we don’t actually want that. What we want to do is group by the [Obj ID] and within the group filter on the [contract type] and then with those results apply some computation. This then needs to link back to the row context in table 2.

 

The only way I can think of doing this is to use the calculated table that I provided the DAX for above. Then add a new calculated column to Table 2 and reference the [amount] column from the calculated table. DAX is “calc col in tbl2” = RELATED(‘calc table’[Amount])

 

Note that you need to create a relationship between Table2 and the calculated table on the [obj id] column.

 

Thanks, Brian

View solution in original post

4 REPLIES 4
bpsearle
Resolver II
Resolver II

Hey,

 

You have described the criteria for the filter that you want to use for your measure. What do you want to calculate with the measure?

 

The reason I ask is I’m not 100% sure if you want a measure or to add a calculated column to Table 2. It depends what you are trying to achieve overall and by that I mean how you want to display this data in your visuals.

 

Thanks, Brian

Hello Brian, though the example i used is quite simple, in actual data, will apply several conditions to table 2. My focus here is if i use a sumx measure for table 2, to only put value for each object id based on the following condition, if such object id contains contract type "prepaid" i will put 0 value, else i will put a value of 100. Basically, im trying to figure out the "in" function through a measure. Let me know if i'm clear with my goal. 

Hi @newbiepowerbi 

How is table 2 produced? Does it already exist with columns in it?

The reason I ask is you can create Table 2 from Table 1 using SUMMARIZE. In my example, I’ve added an amount column to Table 1 so that some computation can be made for the example. You would replace that with whatever it is you need. Here is the example:

Table2 =
SUMMARIZE (
    Table1,
    Table1[Obj ID],
    "Amount", 
    CALCULATE ( 
        SUM ( Table1[Amount] ), 
        Table1[Contract type] = "Accrued" 
        )
)

Thanks, Brian

Hi @newbiepowerbi 

 

I’ve been looking at how you would add a calculated column to Table 2 that will do the calculation you want. However, I’m not sure how to do this. SUMX iterates across rows but we don’t actually want that. What we want to do is group by the [Obj ID] and within the group filter on the [contract type] and then with those results apply some computation. This then needs to link back to the row context in table 2.

 

The only way I can think of doing this is to use the calculated table that I provided the DAX for above. Then add a new calculated column to Table 2 and reference the [amount] column from the calculated table. DAX is “calc col in tbl2” = RELATED(‘calc table’[Amount])

 

Note that you need to create a relationship between Table2 and the calculated table on the [obj id] column.

 

Thanks, Brian

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.

Top Solution Authors