'How to replace a blank value with zero in Power BI matrix?
I have a matrix in the below format, where Online and Offline are measures. I want to replace blank values for Online and Offline with zero. How can I do this?
Online measure DAX (similar for Offline measure)
Online =
VAR sale =
CALCULATE(
SUM('Sales Data'[Sale Amount]),
FILTER(ALL('Sales Data'[Type of Sale]), 'Sales Data'[Type of Sale] = "Online")
)
VAR purch =
CALCULATE(
SUM('Sales Data'[Units Purchased]),
FILTER(ALL('Sales Data'[Type of Sale]), 'Sales Data'[Type of Sale] = "Online")
)
RETURN IF(SELECTEDVALUE(Labels[Metric]) = "Sales Amount", sale, purch)
Solution 1:[1]
In your measures, you will want to specifically set any BLANK() results to 0. Then return those 0's instead of BLANK()'s. Below, I've modified the Online measure that you provided with this adjustment.
Online =
VAR sale =
CALCULATE(
SUM('Sales Data'[Sale Amount]),
FILTER(ALL('Sales Data'[Type of Sale]), 'Sales Data'[Type of Sale] = "Online")
)
VAR saleWithZero = IF(ISBLANK(sale), 0, sale)
VAR purch =
CALCULATE(
SUM('Sales Data'[Units Purchased]),
FILTER(ALL('Sales Data'[Type of Sale]), 'Sales Data'[Type of Sale] = "Online")
)
VAR purchWithZero = IF(ISBLANK(purch), 0, purch)
RETURN IF(SELECTEDVALUE(Labels[Metric]) = "Sales Amount", saleWithZero, purchWithZero)
Below is a sample matrix that I tested this on.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |


