Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Coriel-11
Resolver II
Resolver II

DAX to change blanks to zeroes (and/or override the legend filter)

Hi everyone,
I have two, related data tables. 'New SLA' is like this:

Asking DateMailboxEmails remainingMultiple
03-Oct-24Training8071296
03-Oct-24Digital98
03-Oct-24Shipping00
04-Oct-24Training13211181
04-Oct-24Digital1416
07-Oct-24Training15281583
07-Oct-24Digital2221
08-Oct-24Training21581663
08-Oct-24Digital1418
09-Oct-24Training15281715
09-Oct-24Digital5758
09-Oct-24Shipping00

 

And then a 'Calendar' (i.e. date) table, which is related via 'New SLA'[Asking Date] → 'Calendar'[Date] like this:

DateDayNameDayMnDayMnSort
01-Oct-24Tu1.Oc1001
02-Oct-24We2.Oc1002
03-Oct-24Th3.Oc1003
04-Oct-24Fr4.Oc1004
07-Oct-24Mo7.Oc1007
08-Oct-24Tu8.Oc1008
09-Oct-24We9.Oc1009
10-Oct-24Th10.Oc1010

 

Originally I was trying to use a line chart and get it to look like this:
(Where the colours in the legend relate to the 'New SLA'[Mailbox] column.)

Coriel11_0-1729009399992.png

(to create this I basically had to handpick the "dates" along the x axis via the filter)


Instead, no matter how many variations on DAX measures I tried (must be 50+) I always came down to 2 basic problems. Either there would be gaps for the blue "Shipping" line; or the x axis would expand to include the weekends (where none of the fields had any data).

 

The reason for this is that for several dates, the Shipping mailbox does not have a row, so I either make it force every potential date in range to be a 0 if there is no data, or to put up with the blanks. I have tried using CROSSJOIN() / SUMMARIZE() / ADDCOLUMNS() to create a table within the measure, and using COALESCE(), UNION() etc.

 

I know I could probably create a calculated table, or fix it in PowerQuery, add the values for the x axis into the 'New SLA' table etc. But I guess having invested so much time in this I want to at least learn something.

 

So my question is this: Within the measure, how can I add in the extra rows/data points  so they won't get wiped out by the chart filter context? And/or is there a way to override what I'm calling the legend context, because that seems to ruin all my efforts to ALL() type commands to escape the filter context as I would do normally. How do I get it to work?

 

A sample file is below, featuring a couple of examples of what I have tried and failed and how it turned out.

Dropbox link to .pbix file

Many thanks,

Coriel-11

8 REPLIES 8
ajohnso2
Solution Supplier
Solution Supplier

Can you not just filter weekends out of your date table and convert any remaining blanks (Mon-Fri) to 0?

Thanks @ajohnso2 
This is what I ended up doing in the end, but I felt a little short changed by it. Not only does it not completely cover all viable scenarios (e.g. Christmas Day), but also I feel I should somehow be able to do it without resprting to that and so I guess I'm trying to learn in the process. 
Thanks for your help,

v-bofeng-msft
Community Support
Community Support

Hi @Coriel-11 ,

 

Would you like to use DAX to replace blank values with 0 so they can be displayed in the line chart, and also filter out weekends?If so , please try:

SLA for Chart = If(SELECTEDVALUE('Calendar'[DayName]) in {"Sa","Su"},BLANK(),
IF(SUM('New SLA'[Multiple])<0,
    0,
    DIVIDE(
        SUM('New SLA'[Multiple]),
        SUM('New SLA'[Emails remaining]),
    0)
)+0)

vbofengmsft_0-1729233996057.png

 

Best Regards,
Bof

 

Hi @v-bofeng-msft 
Thanks for your reply.
I hadn't thought of doing it that way – in fact I've not used  in {"A","B"} before. I went away, looked that up and even then used it in something else on Friday, so thanks for that.

I guess this does similar to the filter but it's inside the measure, which I like.

Part of me is still curious, though, as to how you can get it to do it on the basis of there being no values for a particular date. That's not just because then it would also cover national holidays etc but also because I'm curious as to why I can't work outside the legend context.

_AAndrade
Super User
Super User

Hi @Coriel-11,

This is happening because you're using a column that would be considered as categorical type on X-Axis.

If you use the Date column you can change this type to Continuos and the output would be this:

_AAndrade_0-1729153732279.png
If you pretend to use DayMn on the X-Axis change tour Dax measure to this:

_AAndrade_1-1729153856272.png

And the final output woul be the same:

_AAndrade_2-1729153905032.png

 





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Thanks @_AAndrade ,
I appreciate your help. I had tried the first method, but wanted to figure out why it doesn't work. Unfortunately though, when I try your second method (and I remove the DayName filter on the visual) I still get this (with the weekends showing when there is no data), I guess because where I want it to be blank is now a zero.

Coriel11_0-1729184435021.png

It just seems impossible to force in 0s when there's no data for just that stream.
Do you have any other ideas?
Many thanks for taking the time,
Coriel-11

Hi @Coriel-11,

I didn't understand what you're looking for. Could you please explain in more detail what is the desired output?
Because I thought you want to replace blank values to 0 and it was what I did in my example.





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Hi @_AAndrade 
Thanks for your message and sorry if I've not been very clear.

 

I am trying to replace blank values with zeroes, but only in those cases where there is at least 1 non-blank value for the date. So at weekends when all three values are blank, I want them to stay that way, but if (say during the week Training is 123 but there's nothing for shipping, I want it to show 0, not be blank).

I guess I'm particularly interested in how that can be done within a measure (rather than using a visual filter), and especially how the filtering effect of the legend can be overcome because something like the ALL() function doesn't seem to be able to do that.

Not sure if that's any clearer, apologies if not.
Thanks again

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.