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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Arno123
Regular Visitor

empty row with count on related table + 0

Hi

 

My first post, so appologies for the clumsiness.

 

So I have 2 tables, Documents and Attachments.

To keep it simple, documents has 1 relevant column witch is the HeaderId (the ID of the document).

The Attachments also have only 1 relevant column witch is ID

 

So I am looking to have a table where I get how many attachments a certain document has.
looks like this:

HeaderID

NrOfAttachments

Doc1

0

Doc2

5

Doc3

0

Doc4

3

 

The first problem I managed to overcome was showing the rows with a 0 as with the count of the Attachment ID's, rows with 0 would not show.

This I did through a measure on the Documents table where the code is:

 

NrOfAttachments = COUNTROWS(FILTER(documentAttachment, CONTAINS(questionaireQuestions, questionaireQuestions[Id], documentAttachment[No]))) + 0

 

However when I Add the measure to the table to display, I get an empty row. Like this:

HeaderID

NrOfAttachments

 

0

Doc1

0

Doc2

5

Doc3

0

Doc4

3

 

I found a similar issue here: How to remove empty rows but keep zero counts in c... - Microsoft Fabric Community

And tansformed the measure code to:

 

NrOfAttachments =

VAR _a =

    COUNTROWS(FILTER(documentAttachment, CONTAINS(questionaireQuestions, questionaireQuestions[Id], documentAttachment[No]))) + 0

RETURN

    IF ( ISBLANK ( _a ), 0, _a )

 

But that also did not work.

Any one got a solution where I don't have to pollute the filters?

 

Kind regards
Me

1 ACCEPTED SOLUTION
v-xinruzhu-msft
Community Support
Community Support

Hi @Arno123 

After testing, if your data have the blank field, it will return the blank field.

e.g 

vxinruzhumsft_0-1694065539502.png

Then it will return the blank to 0

vxinruzhumsft_1-1694065563954.png

You can check it and change the code to the following

NrOfAttachments =
VAR _a =
    COUNTROWS (
        FILTER (
            documentAttachment,
            CONTAINS (
                questionaireQuestions,
                questionaireQuestions[Id], documentAttachment[No]
            )
        )
    ) + 0
RETURN
    IF (
        SELECTEDVALUE ( questionaireQuestions[HeaderID] ) <> BLANK,
        IF ( ISBLANK ( _a ), 0, _a )
    )

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-xinruzhu-msft
Community Support
Community Support

Hi @Arno123 

After testing, if your data have the blank field, it will return the blank field.

e.g 

vxinruzhumsft_0-1694065539502.png

Then it will return the blank to 0

vxinruzhumsft_1-1694065563954.png

You can check it and change the code to the following

NrOfAttachments =
VAR _a =
    COUNTROWS (
        FILTER (
            documentAttachment,
            CONTAINS (
                questionaireQuestions,
                questionaireQuestions[Id], documentAttachment[No]
            )
        )
    ) + 0
RETURN
    IF (
        SELECTEDVALUE ( questionaireQuestions[HeaderID] ) <> BLANK,
        IF ( ISBLANK ( _a ), 0, _a )
    )

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Ahmedx
Super User
Super User

I'm not sure, but perhaps something like this will help solve your problem

https://youtu.be/eosB-n7m2x8

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors