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
ronaldbalza2023
Continued Contributor
Continued Contributor

Replacing blank values with zero

Hi everyone, having a hard time trying to figuring out this one and appreciated the help!

Question: How can I replace the blank/empty rows with zero? I highlighted the empty rows with grey for the meantime and wanted to replace it by zero.

ronaldbalza2023_0-1633651078722.png

This measure removes the columns that has empty values

P&L (No Blanks) = CALCULATE( IF( [P&L] = 0, BLANK(), [P&L]))

 These are the measures of P&L

P&L = 
(
    CALCULATE (
        SUM ( 'Invoices'[Line Amount FX Calculation] ),
        FILTER (
            'Accounts',
            Accounts[Class] = "Revenue"
                || Accounts[Class] = "Expense"
        ), USERELATIONSHIP( Invoices[Invoice Line ID], 'Tracking Category CONNECTIONS'[ID])
    )
) - [P&L - Credit Notes] + [P&L (Journals)]
P&L - Credit Notes = 
CALCULATE (
    SUM ( 'Credit Notes'[Line Amount Credit Note Calculation FX] ),
    FILTER (
        'Accounts',
        'Accounts'[Class] = "Revenue"
            || Accounts[Class] = "Expense"
    ), USERELATIONSHIP( 'Credit Notes'[Credit Note Line ID], 'Tracking Category CONNECTIONS'[ID])
)
P&L (Journals) = 
CALCULATE ( 0 - ( SUM ( 'Journals'[Net Amount FX] ) ),
    FILTER ( 'Journals', 'Journals'[Split] = "JOURNALS" ),
    FILTER (
        'Accounts',
        'Accounts'[Class] = "Revenue"
            || Accounts[Class] = "Expense"
    ), USERELATIONSHIP( Journals[ID], 'Tracking Category CONNECTIONS'[ID])
) 

 

5 ACCEPTED SOLUTIONS
AllisonKennedy
Super User
Super User

@ronaldbalza2023 You're converting the 0s to blanks with the P&L (no blanks) measure. Are you saying you want that back to 0? Can you simply use the P&L measure?

 

The problem is, that you have a matrix so it will replace ALL rows with zero - how do you specify which rows you want to show or not?

 

You may be able to work with an IF() statement, but we need to know which columns you're using in that matrix visual please and you could use that context to filter out rows where the total row is blank, otherwise put 0 - is that what you mean?


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

@ronaldbalza2023  Sorry, I was trying with a simplified version of [P&L] but you're right it doesn't work in your measures. 

 

Try updating the [P&L (No Blanks)] measure and use that in your visual instead:

 

P&L (No Blanks) =
VAR _ColSubTotal = CALCULATE([P&L], ALL(DimAccount[Account Type), ALL(DimAccount[Name]))
VAR _Result =
IF(_ColSubTotal <> 0, [P&L])
RETURN _Result
 
I don't know what table the Account Type and Name are coming from, so you may need to update that part of the measure.

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

@ronaldbalza2023 I thought your [P&L] measure already had the $0 included in it? So the $0 should display if you've got the ColSubtotal part correct....

 

You could try adding the zero back in: 

 

P&L (No Blanks) =
VAR _ColSubTotal = CALCULATE([P&L], ALL(DimAccount[Account Type), ALL(DimAccount[Name]))
VAR _Result =
IF(_ColSubTotal <> 0, [P&L]+0)
RETURN _Result

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

That's because they are blank for that account type. Do you have a DimAccount table?

 

Can try replacing the ALL filters with just 

 

ALL(DimAccount)


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

Hi @AllisonKennedy , hooray! after a gruelling nights spending time with this 🙂 Thanks so much for your help. 

View solution in original post

23 REPLIES 23
ronaldbalza2023
Continued Contributor
Continued Contributor

Hi everyone, I wanted to replace the blank values with zero. How can I achieve that? The old trick + 0 seems not working. Here's my measures. Thanks for the help 🙂

P&L = 
(
    CALCULATE (
        SUM ( 'Invoices'[Line Amount FX Calculation] ),
        FILTER (
            'Accounts',
            Accounts[Class] = "Revenue"
                || Accounts[Class] = "Expense"
        ), USERELATIONSHIP( Invoices[Invoice Line ID], 'Tracking Category CONNECTIONS'[ID])
    )
) - [P&L - Credit Notes] + [P&L (Journals)] + 0
P&L - Credit Notes = 
CALCULATE (
    SUM ( 'Credit Notes'[Line Amount Credit Note Calculation FX] ),
    FILTER (
        'Accounts',
        'Accounts'[Class] = "Revenue"
            || Accounts[Class] = "Expense"
    ), USERELATIONSHIP( 'Credit Notes'[Credit Note Line ID], 'Tracking Category CONNECTIONS'[ID])
) + 0
P&L (Journals) = 
CALCULATE (
    0 - ( SUM ( 'Journals'[Net Amount FX] ) ),
    FILTER ( 'Journals', 'Journals'[Split] = "JOURNALS" ),
    FILTER (
        'Accounts',
        'Accounts'[Class] = "Revenue"
            || Accounts[Class] = "Expense"
    ), USERELATIONSHIP( Journals[ID], 'Tracking Category CONNECTIONS'[ID])
) + 0

 

@ronaldbalza2023, just found something that may resolve the issue:

 

Measure = IF(ISBLANK([P&L]),BLANK(),IF(ISBLANK([P&L]),0,[P&L]))

 

The issue that may be causing the misunderstanding is that there may be blanks in your outputs that are valid blanks and therefore it's testing to see if a blank exists, if it does, convert to 0, otherwise deliver the output of the measure.  

 

Hope this helps!

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Hi @ronaldbalza2023,

I would write the measure as such:

 

P&L = 
IF (
	(
		CALCULATE (
			SUM ( 'Invoices'[Line Amount FX Calculation] ),
			FILTER (
				'Accounts',
				Accounts[Class] = "Revenue"
					|| Accounts[Class] = "Expense"
			), USERELATIONSHIP( Invoices[Invoice Line ID], 'Tracking Category CONNECTIONS'[ID])
		)
	) - [P&L - Credit Notes] + [P&L (Journals)] ) = 0 , 0 ,
	(
    CALCULATE (
        SUM ( 'Invoices'[Line Amount FX Calculation] ),
        FILTER (
            'Accounts',
            Accounts[Class] = "Revenue"
                || Accounts[Class] = "Expense"
        ), USERELATIONSHIP( Invoices[Invoice Line ID], 'Tracking Category CONNECTIONS'[ID])
    )
) - [P&L - Credit Notes] + [P&L (Journals)] )

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Hi @ronaldbalza2023,

The +0 works sometimes but not in all instances where filters are being used in meausres. I'd recommend doing the following:

 

MeasureName = IF ( [Your Measure] = 0 , 0 , [Your Measure] )

An example of it in use is:

TheoC_0-1633587452789.png

 

Hope this helps 🙂

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Hi @TheoC , thanks for taking the time on this. It works however, all the columns that has zero values appeared and the totals column on the far right disappeared. How can I removed the columns with zero values and bring back the totals column? I have filtered the values that is not 0. 

ronaldbalza2023_0-1633587744919.png

 

 

ronaldbalza2023_1-1633587900053.png

ronaldbalza2023_2-1633587959277.png

 

 

Hi @ronaldbalza2023, did you remove the +0 from your measures?

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

@TheoC when I use blank(), it removes the columns with zeroes and the total columns appears. However, I wanted to fill these blanks here with zero.

ronaldbalza2023_0-1633589293965.png

ronaldbalza2023_1-1633589311310.png

 

 

@ronaldbalza2023, try using 

IF ( ISBLANK ( [P&L] ) , 0 , [P&L] )

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

@TheoC yes Sir, I did. Still the same.

If the below doesn't work, then there is something else that may be the issue mate. The logic is based on your formula, filters and relationships. All the adjustment is doing is saying return 0 if it's blank, else return the output.  Without having access to the PBIX, it will be difficult for me to be of any assistance and I'd be wasting your time... sorry @ronaldbalza2023 

P&L = 
IF (
	(
		CALCULATE (
			SUM ( 'Invoices'[Line Amount FX Calculation] ),
			FILTER (
				'Accounts',
				Accounts[Class] = "Revenue"
					|| Accounts[Class] = "Expense"
			), USERELATIONSHIP( Invoices[Invoice Line ID], 'Tracking Category CONNECTIONS'[ID])
		)
	) - [P&L - Credit Notes] + [P&L (Journals)] ) = 0 , 0 ,
	(
    CALCULATE (
        SUM ( 'Invoices'[Line Amount FX Calculation] ),
        FILTER (
            'Accounts',
            Accounts[Class] = "Revenue"
                || Accounts[Class] = "Expense"
        ), USERELATIONSHIP( Invoices[Invoice Line ID], 'Tracking Category CONNECTIONS'[ID])
    )
) - [P&L - Credit Notes] + [P&L (Journals)] )

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Hi @ronaldbalza2023, can you remove the "Calculate" and just leave the IF...

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

@TheoC still doing the same. Nothing really happened.

AllisonKennedy
Super User
Super User

@ronaldbalza2023  I would maybe try using the [P&L] measure in your matrix values, and put the [P&L (no blanks)] in the Filters on this visual and filter for not blank.


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

@AllisonKennedy , thank you for taking the time on this. When I  am using the [P&L] measure as you can see below snapshot, empty columns with zero values appears and the Total Column on the far right of the table disappear.

 

Now, with this case, I wanted to remove the columns that are having with zeros/empty values.

ronaldbalza2023_1-1633654464251.png

ronaldbalza2023_2-1633654517135.png

 

 

 

@ronaldbalza2023  Now just add the P&L (No Blanks) to your matrix under 'filters on this visual' - you'll need to drag and drop it in manually: 

 

AllisonKennedy_0-1633656096011.png

 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

@AllisonKennedy apologies, forgot to mention I did it as well with no luck. 

ronaldbalza2023_0-1633656511420.png

ronaldbalza2023_1-1633656534133.png

 

 

@ronaldbalza2023  Sorry, I was trying with a simplified version of [P&L] but you're right it doesn't work in your measures. 

 

Try updating the [P&L (No Blanks)] measure and use that in your visual instead:

 

P&L (No Blanks) =
VAR _ColSubTotal = CALCULATE([P&L], ALL(DimAccount[Account Type), ALL(DimAccount[Name]))
VAR _Result =
IF(_ColSubTotal <> 0, [P&L])
RETURN _Result
 
I don't know what table the Account Type and Name are coming from, so you may need to update that part of the measure.

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Hi @AllisonKennedy  really appreciated your time taking on this. It removes the column with zero values thanks. How can I now replace the nil/blank rows with zero? Thanks so much!

ronaldbalza2023_0-1633664637890.png

 

@ronaldbalza2023 I thought your [P&L] measure already had the $0 included in it? So the $0 should display if you've got the ColSubtotal part correct....

 

You could try adding the zero back in: 

 

P&L (No Blanks) =
VAR _ColSubTotal = CALCULATE([P&L], ALL(DimAccount[Account Type), ALL(DimAccount[Name]))
VAR _Result =
IF(_ColSubTotal <> 0, [P&L]+0)
RETURN _Result

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Hi @AllisonKennedy , doing this getting back the rows with zeroes, however, there's some rows were empty which is weird. 

ronaldbalza2023_0-1633767971784.png

 

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.

Top Solution Authors