Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
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:
Solved! Go to Solution.
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))
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!!
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
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
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.
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.
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.