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
Mattpar
Frequent Visitor

measure with related & error condition

Hi,

I have two tables (Transactions and options) linked to each other with many to one relationship through "Change No" column. 

 

There are some items in my transactions table that do not have a matching value in options table. Therefore, when I use "options" column values from options table and Transaction_id from transactions table I get a rov with a blank cell for these items.

 

What I am trying to do is to call these blank row items a "No options" category.

 

I managed to do this by creating a calculated column in my transactions table, using;

 

Options = IF('transactions'[Variations/Base Scope]="Variations",
LOOKUPVALUE('Options'[Options],' options'[Change Number], 'transactions'[Change No], "NO OPTION"))

 

If I pull this calculated column to my rows in report view, I can see what I want.

 

Options        Count of Transaction_id 

No Option      7

Option-1        3

Option-2        3

 

However, my actual data set is quite large and instead of creating a calculated column I would like to solve this with a measure.

 

I tried using Calculate and Related functions together but I could not figure out how to enter the if, error and related column condition.

 

Appreciate for the help. 

 

Below are my sample tables;

 

Transactions table;

 

transactions.JPG

Options table :

variations.JPG

model view

 

model view.JPG

 

Report view - table

report view.JPG

 

3 REPLIES 3
v-diye-msft
Community Support
Community Support

Hi @Mattpar 

 

If you've fixed the issue on your own please kindly share your solution. if the above posts help, please kindly mark it as a solution to help others find it more quickly.thanks!

If the question still exists, please kindly share more details about your data, simple file/dummy pbix is preferable.

 

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.
Ashish_Mathur
Super User
Super User

Hi,

The variations 2 table should be build from the transactions 2 table.  Make a copy of the transactions 2 table and remove all columns other than the Change No column (this will now be your variations 2 table ).  Remove duplicates from this column.  In another column of this table, enter option-1.  Now create a relationship between these 2 tables.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
d_gosbell
Super User
Super User

So you could do this with a measure, BUT you would need to have a row in your options table for the "NO OPTIONS" value. This is because measures can change the values returned against an existing row, but they cannot generate new rows on the fly.

 

If you have a NO OPTIONS value in your table such a measure would look something like the following:

Measure = if (SELECTEDVALUE(Options[Option]) == "NO OPTIONS" ,CALCULATE(COUNTROWS(Transactions),ALL(Transactions), ISBLANK(('Options'[Option]))),
 if( ISBLANK( SELECTEDVALUE('Options'[Option]) ),blank(), COUNTROWS(Transactions)))

 Basically this is 2 IF statements, one checks if the current row is the "NO OPTIONS" value and returns the value for the blank, unmapped values, the second IF returns a blank for the blank options.

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.