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
Anonymous
Not applicable

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

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

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))
Anonymous
Not applicable

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

Anonymous
Not applicable

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 @Anonymous ,

 

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.
Anonymous
Not applicable

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 @Anonymous ,

 

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.
Anonymous
Not applicable

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