Forum Discussion
Measure by comparing two columns in two different table
- Anonymous8 years ago
This solution only requires Tables 1 and 2. No bridge table, no relationships.
Add this calculated column to Table 1 - Spend:
Preferred = VAR Test = COUNTROWS ( FILTER ( PreferredSupplier, PreferredSupplier[Supplier] = Spend[Supplier] && PreferredSupplier[Category] = Spend[Category] ) ) RETURN IF ( Test = 1, "Yes", "No" )The Test variable checks to see if there is a match against the Preferred Supplier table, matching both on Supplier and Category. If there is, 1 row will be returned. Then the result in the column will be "Yes".
Then you can create the following measures:
[Total Spend] = SUM ( Spend[Spend] )
[Approved Spend] = CALCULATE ( [Total Spend], Spend[Preferred] = "Yes" )
[% Approved Spend] = DIVIDE ( [Approved Spend], [Total Spend] )
- 8 years ago
Hi ChrisHaas
Your solution is working fine with small correction but I dont know why
Preferred =
VAR Test =
COUNTROWS (
FILTER (
PreferredSupplier,
PreferredSupplier[Supplier] = Spend[Supplier]
&& PreferredSupplier[Category] = Spend[Category]
)
)
RETURN
IF ( Test = 1, "Yes", "No" )In the above calculated column I chnaged the If statement as
IF ( Test = 0, "No", "Yes" )
remining everything I keep as you mentioned and working perfect.
But I said I still dont know what and why it gave wrong value first and right value once I changed the if statement
Thanks for the solution, it works now
This solution only requires Tables 1 and 2. No bridge table, no relationships.
Add this calculated column to Table 1 - Spend:
Preferred =
VAR Test =
COUNTROWS (
FILTER (
PreferredSupplier,
PreferredSupplier[Supplier] = Spend[Supplier]
&& PreferredSupplier[Category] = Spend[Category]
)
)
RETURN
IF ( Test = 1, "Yes", "No" )
The Test variable checks to see if there is a match against the Preferred Supplier table, matching both on Supplier and Category. If there is, 1 row will be returned. Then the result in the column will be "Yes".
Then you can create the following measures:
[Total Spend] = SUM ( Spend[Spend] )
[Approved Spend] = CALCULATE ( [Total Spend], Spend[Preferred] = "Yes" )
[% Approved Spend] = DIVIDE ( [Approved Spend], [Total Spend] )
- mahra-in8 years agoHelper II
Hi ChrisHaas
Your solution is working fine with small correction but I dont know why
Preferred =
VAR Test =
COUNTROWS (
FILTER (
PreferredSupplier,
PreferredSupplier[Supplier] = Spend[Supplier]
&& PreferredSupplier[Category] = Spend[Category]
)
)
RETURN
IF ( Test = 1, "Yes", "No" )In the above calculated column I chnaged the If statement as
IF ( Test = 0, "No", "Yes" )
remining everything I keep as you mentioned and working perfect.
But I said I still dont know what and why it gave wrong value first and right value once I changed the if statement
Thanks for the solution, it works now
- Mai_Nashaat5 years agoHelper II
In this step
RETURN IF ( Test = 1, "Yes", "No" )what if I want to return value from table preferred supplier, what can I do?