cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
VictorHMSouza
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:

VictorHMSouza_0-1647522113750.png

Chart with zeros:

VictorHMSouza_3-1647522557829.png

 

Chart that I need:

VictorHMSouza_2-1647522390238.png

 

1 ACCEPTED SOLUTION
johnt75
Solution Sage
Solution Sage

Add a new column to your date table

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

then create your measure as

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

View solution in original post

9 REPLIES 9
johnt75
Solution Sage
Solution Sage

Add a new column to your date table

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

then create your measure as

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

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

VictorHMSouza
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.

Hi @VictorHMSouza ,

 

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.

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). 

Hi @VictorHMSouza ,

 

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.

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.

VictorHMSouza_0-1648209300977.png

 

Jihwan_Kim
Super User
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.

 

Picture1.png

 

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.


Go to My LinkedIn Page


Whitewater100
Solution Sage
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.

Helpful resources

Announcements
August 2022 update 768x460.jpg

Check it Out!

Click here to learn more about the August 2022 updates!

August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors