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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

How to remove blank row when using a measure to display count of rows in related tables

Hi All,

I have a very simple model comprising of the following tables.

Model

sau001_0-1610756892123.png

 

This is the classic many-many relationship.  1 Author can have many Titles and vice-versa.

 

 

Authors

IDAuthor
100John Doe
200Jane Doe
300Adam Smith
400William Shakespeare

 

Titles

IDTitle
10Julius Caesar
20The merchant of Venice
30Some book 1
40Some book 2
50Wealth of Nations
60Romeo Juliet

 

AuthorTitles

AuthorIDTitleID
40010
40020
30050
40060

 

MeasureCount = 
var actual_count=CALCULATE(COUNTROWS(RELATEDTABLE(Titles)))
return IF(ISBLANK(actual_count),0,actual_count )

 

 

sau001_0-1610757768097.png

 

How do I remove the blank row?

 

Thanks,

Sau

 

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

Hi, @parry2k , as mentioned in my former reply, Titles is a lookup table, thus the relationship between Titles and AuthorTitles changes to 1:* accordingly. In order to make a filtering propagate reversely from AuthorTitles(*) to Titles(1), I use an expanded table as filter modifier here. Of coz it's out of conceptual illustration to author such a verbose measure whereas your concise solution is good enough to tackle this practical issue.


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

14 REPLIES 14
parry2k
Super User
Super User

@Anonymous, although you have a solution, here is the updated measure

 

Count = COUNTROWS ( AuthorTitle ) + IF ( NOT ISBLANK ( MAX ( Authors[Author] ) ), 0 )

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hello @Anonymous ,

Total Title =
VAR TotalTitle = COUNTROWS(AuthorTtiles)
RETURN
IF( ISBLANK( TotalTitle ), 0, TotalTitle )
Capture.PNG
Capture1.PNG
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hello @Ashish_Mathur ,

 

Thanks so much for looking into this.

 

Problem 1

I downloaded you PBI.  This is what  I see.

sau001_0-1610796107044.png

I can see that you have constructed a Table visual using the Titles table and then added the custom Measure.

This eliminates the blank row. But, it does not show me the authors with 0 titles. (Jane Doe and John Doe)

 

Problem 2

I tried your DAX expression by creating a DAX expression in the Authors table

sau001_2-1610796652715.png

 

The blank row has come up again.

 

 

Looking at your response, you appear to have fixed this. What did you do and what did I miss?

 

Regards,

Sau

 

 

Hi,

I am confused by your reply.  Have i answere your question?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hello @Ashish_Mathur ,

Thanks so much for looking into this problem.  As mentioned by @CNENFRNL  , the real problem was with the cardinality of the relationship.  

Cheers,

Sau

 

Anonymous
Not applicable

Hello @Ashish_Mathur ,

I want to stress that while there was an issue with the cardinality of the relationship, your suggestion was very valuable in fixing the blank row issue. I wish I could accept both answers as the solution.

 

Thank you,

Sau

 

You are welcome.


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

@CNENFRNL I don't understand the logic why to pass the 2nd parameter to calculate and as a matter of fact, why even calculate is required?? Not sure what I'm missing here.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

CNENFRNL
Community Champion
Community Champion

Hi, @parry2k , as mentioned in my former reply, Titles is a lookup table, thus the relationship between Titles and AuthorTitles changes to 1:* accordingly. In order to make a filtering propagate reversely from AuthorTitles(*) to Titles(1), I use an expanded table as filter modifier here. Of coz it's out of conceptual illustration to author such a verbose measure whereas your concise solution is good enough to tackle this practical issue.


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

CNENFRNL
Community Champion
Community Champion

Hi, @Anonymous , in theory, TITLES table should be a lookup table; thus the relationships in the data model is supposed to be built this way,

Untitled.png

You might want to try this measure

Count = CALCULATE( COUNTROWS( Titles ), CALCULATETABLE( AuthorTitles ) )

Screenshot 2021-01-16 052701.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Anonymous
Not applicable

 

Hello @CNENFRNL ,

 

You were right about the  change of relationship cardinality.

Should be 1-many  and not 1-1.

i.e. One Title has many Authors

 

sau001_3-1610797468202.png

I used the DAX expression from   @Ashish_Mathur 

 

CountPbiCommunity = 
VAR TotalTitle = COUNTROWS(AuthorTitles)
return IF( ISBLANK( TotalTitle ), 0, TotalTitle )

 

@Ashish_Mathur  , @CNENFRNL 

Thanks both.

 

 

 

parry2k
Super User
Super User

@Anonymous not sure what your expected result is? It should show only 4 rows, 30 and 40 will not show, and not sure why you have that measure, the measure should be  as simple as this

 

Count = COUNTROWS ( AuthorTitles )

 

In visualization, use Id and Author from author table and drop above measure and you should get 4 books.

 

 

image.png

 

Check my latest blog post Year-2020, Pandemic, Power BI and Beyond to get a summary of my favourite Power BI feature releases in 2020

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hi @parry2k ,

This removes the blank row. But, it does not render the 'zero'.   

 

sau001_5-1610798211873.png

The relationship cardinality was the issue. 

 

Thank you,

Sau

 

 

 

 

 

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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