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
Anonymous
Not applicable

Unexpected display results in a Matrix visual when referencing a Measure containing IF

I am getting unexpected results in the displayed Matrix visual when I display a Measure which contains an IF statement.

 

My sample data:

 

dimension table  - Customers 

    Cust No - rows for customer numbers A, B, and C

    Cust Name

dimension table - Date Ref

    Date - rows for each and every day for 2019 and 2020

transaction table - Transactions

    Date

    Cust No

    Revenue

    Gross Profit

    [Note: I only have transactions in the table for Cust No = A]

Measures

    Total Revenue = sumx(Transactions, Transactions[Revenue])

    Total Gross Profit = sumx(Transactions, Transactions[Gross Profit])

    Total Gross Profit % = divide([Total Gross Profit],[Total Revenue],0)

Relationships

    Customers 1:many to Transactions linked on Cust No

    Date Ref 1:many to Transactions linked on Date

 

At this point, in a Matrix visual with Customers[Cust No] for rows, Date Ref[Date] with hierachy Year, Month for columns, and Total Revenue, Total Gross Profit, Total Gross Profit %, everything displays as expected.  As there are only transactions for Cust No = A in the transaciton table, only Cust No = A is displayed (even though there are Cust No B & C in the Customers table).  As there are only transacitons for a few dates in a few months, only the months with transacitons are displayed (even though there are dates for every date across two years in the Date Ref table) This is true whether only displaying totals for Year or expanding levels to also show Month.

 

Objective: I do want to evaluate the monthly aggregate gross profit percentage in the measure Total Gross Profit % and then display only those items (monthly totals) where the measure results are above (or below) a specific value (e.g., 20%)

 

Problem: When I create an additional measure Above GP% Target = if([Total Gross Profit %] > 0.20, True, False), and then place this in my Matrix visual, the displayed results of Above GP% Target are correct.  However, the displayed rows expand to include every customer that is in the Customers table, even though there are no transactions for many customers in that table.  And the displayed columns expand to include every month in the Date Ref table, even though there are no transactions for many of the dates in that table.  Further more, if I apply a filter to the visual in the Filters to filter the Above GP% Target based on True or False, the resulting display is not correct at all.  Likewise, if I filter directly on the measure Total Gross Profit to achieve my objective instead of filtering on the additioal measure Above GP% Target, the resulting display is not correct.

 

I suspect the issue is either something with "context" that I am not understanding - or something with IF statements inside of measures.  Is there any guidance on this problem?

 

Many thanks,

 

 

1 ACCEPTED SOLUTION

Very interesting.

 

Here's a "solution".  need to refine it.

 

Above GP% Target = switch(true(), isblank([Total Gross Profit %]),BLANK(),[Total Gross Profit %] > 0.20, "True", "False")

View solution in original post

9 REPLIES 9
lbendlin
Super User
Super User

Your measure 

 

Above GP% Target = if([Total Gross Profit %] > 0.20, True, False)

 

will result in "False"  for missing values of [Total Gross Profit %].  

 

To avoid that , check for blanks.

 

Above GP% Target = switch(true(), isblank([Total Gross Profit %]),blank(),[Total Gross Profit %] > 0.20, True, False)

Anonymous
Not applicable

Thanks Ibendlin.  I do see your logic that the simple IF statement will return false anytime the Total Gross Profit % does not have data to calculate (such as dates in the Date Ref table or customers in the Customer with no related transactions).  However, I tried the Switch approach you noted below, and the results are still expanding the matrix with columns (representing all dates in the Date Ref table) and with rows (representing all customers in the Customer table) even when there is no related transaction in the Transaction table.  It looks like this always evaluates to False, except when there is transaction data present and the Total Gross Profit % is above the 20% threshold.  It is like the isblank([Total Gross Profit %]) function does not evaluate True in those situations where no Transactions exist and instead the logic falls through to the exception clause in the switch statement.

 

Did I misunderstand your suggestion?  Any other ideas?

 

provide some (sanitized) sample data so we can have a closer look.

Anonymous
Not applicable

Thanks Ibendlin.

Below is a screen shot of several table visuals.

Blue - the dimision or reference tables

Purple - the facts or transaction tables

Yellow - an example of the expanded information when adding the Above GP% Target to a table visual

Red - the example of th eexpanded rows and columns when adding the Above GP% Target to a martix visual

 

The second screen shot shows the expected results for rows and columns when the Above GP% Target measure is not included.

Thanks, PBI Community Question.png

PBI Community Question 2.png

Anonymous
Not applicable

Below are the tables and measures.  The output visuals showing the problem are earlier in the thread.

 

Thanks,

 

Customers table

Cust NoCust
AABC
BBCD
CCDE
DDEF


Subset of Date Reference table - includes all dates tha match transactions plus some others outside that

DateYearQuarterOfYearMonthOfYearDayOfMonth
12/15/2019201941215
12/31/2019201941231
1/1/20202020111
1/2/20202020112
1/3/20202020113
1/4/20202020114
1/5/20202020115
1/31/202020201131
2/1/20202020121
2/15/202020201215
2/29/202020201229
3/1/20202020131
3/31/202020201331
4/1/20202020241
4/2/20202020242
4/30/202020202430
5/1/20202020251
5/15/202020202515

 

Transaction table ('Margin Details')

Cust NoDateRevGross Profit
A1/1/202010011
A1/2/20201007
A2/1/20201009
A2/15/202010013
A3/1/202010012
A4/2/20201008

 

aTotal Revenue = sumx('Margin Details','Margin Details'[Rev])
aTotal Gross Profit = sumx('Margin Details','Margin Details'[Gross Profit])
aTotal Gross Profit % = divide([aTotal Gross Profit],[aTotal Revenue],0)
aAbove GP% Target = switch(TRUE,
ISBLANK([aTotal Gross Profit %]),blank(),
[aTotal Gross Profit %]>0.1,TRUE,
FALSE)

Very interesting.

 

Here's a "solution".  need to refine it.

 

Above GP% Target = switch(true(), isblank([Total Gross Profit %]),BLANK(),[Total Gross Profit %] > 0.20, "True", "False")
Anonymous
Not applicable

Thanks for the solution.  It is interesting that the text values "True" or "False" work correctly while the logical values of True / True() or False / False() cause the problem outlined below.  I'm interested to see if any have more details on why that is.

 

Agree. The measure also didn't feel very fast, I am sure there are better ways to write it.

sorry I wasn't clear. Sample data in usable form (either pasted as table here, or attached). Not screenshots.

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.