cancel
Showing results for
Did you mean:
Frequent Visitor

## Replacing blank with 0 with a condition

So I have a chart that displays a count in the Y axxis and the time in the X axxis and I want to replace the blank values with zeros but only when the month already passed or if it is the month we are in.

Chart with blank values:

Chart with zeros:

Chart that I need:

1 ACCEPTED SOLUTION
Solution Sage

``Current month or before = IF( [Date] <= EOMONTH(TODAY(), 0), 1, 0)``

``DB Count = IF( SELECTEDVALUE('Date'[Current month or before]) = 1, COALESCE( COUNTROWS(DB),0))``
9 REPLIES 9
Solution Sage

``Current month or before = IF( [Date] <= EOMONTH(TODAY(), 0), 1, 0)``

``DB Count = IF( SELECTEDVALUE('Date'[Current month or before]) = 1, COALESCE( COUNTROWS(DB),0))``
Frequent Visitor

It worked just as expected! Thank you so much!!

Frequent Visitor

Neither of the answers solved my problem, so I will try to clarify what I need.
I have a bunch of tables ready to use but the most important ones are: DB, Calendar and Planning.
The red line in the chart is based on the planned values, the blue one is a count of the DB table.
In the first chart, the DAX for counting on DB table is: DB COUNT = COUNT(DB[NUMBER]), so if I have a total count of zero in a specific month it appears blank.
In the second one, the DAX is: DB COUNT = COUNT(DB[NUMBER])+0, but this formula calculates values in the future (we are in march but the chart shows values in april, may and so on).
I couldn't find a way to replace the blanks values with zeros but just until our current month.

Community Support

You could simply add an if condition.

DB COUNT =
var _max = maxx(allselected('DB'),[month])
return
IF(selectedvalue('calendar'[month])<=_max,
COUNT(DB[NUMBER])+0, blank())

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
Frequent Visitor

It seems a great method but this chart does not show only 2022 values but 2021 values as well. So I think this wouldn't work because it would show 12 as the _max value (because of past years).

Community Support

Do you have date column in DB table?

DB COUNT =
var _max = Format(maxx(allselected('DB'),[date]),"YYYYMM")
return
IF(Format(selectedvalue('calendar'[date]),"YYYYMM")<=_max,
COUNT(DB[NUMBER])+0, blank())

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
Frequent Visitor

This solution almost worked but the chart keep showing this blue line and a 0 value on 2022/December instead of ending on 2022/March.

Super User

Hi,

I am not sure if I understand your question correctly, but I tried to create a sample pbix file like below.

I hope the below picture and the attached pbix file help to have some idea to implement it to your model.

Please check the below picture and the attached pbix file.

``````expected result measure: =
VAR currentdate =
MAX ( Data[Date] )
VAR mindate =
CALCULATE ( MIN ( Data[Date] ), FILTER ( ALL ( Data ), Data[Qty] <> 0 ) )
VAR maxdate =
CALCULATE ( MAX ( Data[Date] ), FILTER ( ALL ( Data ), Data[Qty] <> 0 ) )
RETURN
IF (
currentdate >= mindate
&& currentdate <= maxdate,
SUM ( Data[Qty] ) + 0,
BLANK ()
)
``````

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.

Solution Sage

Hi:

For the measure you want to truncate, consider another measure that is stopping correctly then

Answer for measure with zeros = IF(ISBLANK([measure that stops correctly]), BLANK, [put the measure here that has the zeros])

It will behave the way you want.

Announcements