cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Plot zero when there is no data in line chart

Month = month('Shiptracking history'[Date])

year = year('Shiptracking history'[Date])

MovingAverage = calculate(sum('Shiptracking history'[Production+0]),DATESINPERIOD('Shiptracking history'[Date],LASTDATE('Shiptracking history'[Date]),-10,DAY))/10

Production+0 = 'Shiptracking history'[Production] + 0

Hi guys,

 

I am editing my post and providing you with more detail to make it easier for you to understand and reproduce what I am trying to do. It is not difficult but I cannot make it work. I have simplified my post as much as possible, hopefully it makes sense. The data is below. I have also pasted some screen shots that will be helpful. I am trying to generate two line charts. First, plot the total production by month. Second, plot moving average of production by day, Charts should plot every month and every day evenb if production is zero. FYI: There is no data on days when there was no production, and charts should plot zero on those days. However, Power BI seems to cut the line on the monthly chart and interpolate linearly on the daily moving average chart. Does anyone know how to sort this out? I want a continuous line on the monthly chart that was to zero in March, and a continuous moving average with value equal to zero whenever there is no data.

 

I have tried adding +0 to the measures, I have tried selecting "show items with no data" on the axis (FYI: The moving average needs to have continuous axis). I have also replaced any null with zeros in the query editor. No success so far. Hopefully one of you will solve it!

 

Thanks a lot

 

Ric

 

Monthly chart needs to go to zero in MarchMonthly chart needs to go to zero in MarchDaily moving average needs to go to zero in MarchDaily moving average needs to go to zero in March

 

 

ProductionDate
76321.5001 Sep 2018 04:23:49
66500.0928 Aug 2018 02:18:59
81134.5025 Aug 2018 14:07:46
76908.4122 Aug 2018 15:01:31
69360.7219 Aug 2018 05:43:25
72032.4015 Aug 2018 15:52:47
77132.5413 Aug 2018 06:34:13
80747.5910 Aug 2018 04:56:34
67683.4508 Aug 2018 01:15:07
63708.3903 Aug 2018 04:03:53
78192.1001 Aug 2018 03:03:38
81134.5028 Jul 2018 13:22:14
73741.5024 Jul 2018 13:54:27
77804.0421 Jul 2018 10:09:47
66500.0918 Jul 2018 05:43:20
78608.7315 Jul 2018 09:58:07
66411.1312 Jul 2018 06:10:15
79039.0010 Jul 2018 11:23:34
73400.7206 Jul 2018 14:06:05
 06 Jul 2018 14:06:05
78192.1004 Jul 2018 19:48:11
78856.5801 Jul 2018 22:09:48
70240.1826 Jun 2018 20:15:01
78123.0725 Jun 2018 18:02:48
77591.0021 Jun 2018 21:28:23
80161.5018 Jun 2018 05:52:49
67358.5015 Jun 2018 21:09:56
78429.0611 Jun 2018 21:51:47
78345.4308 Jun 2018 05:42:45
66031.0003 Jun 2018 22:39:17
76804.0001 Jun 2018 05:17:36
80148.0029 May 2018 04:22:55
77931.6326 May 2018 01:43:00
76704.0023 May 2018 01:56:34
65953.0019 May 2018 17:09:19
78429.0616 May 2018 21:29:50
76570.9512 May 2018 22:00:39
73760.2511 May 2018 13:23:04
76856.0007 May 2018 05:22:09
78160.0004 May 2018 06:36:44
79430.0030 Apr 2018 05:41:29
78608.7326 Apr 2018 20:54:58
76128.3416 Apr 2018 02:04:09
80134.0023 Feb 2018 20:53:52
78555.0022 Feb 2018 00:06:46
69700.0018 Feb 2018 03:55:36
67025.0015 Feb 2018 20:56:57
78877.0013 Feb 2018 20:40:43
66464.0009 Feb 2018 20:11:00
65614.0006 Feb 2018 06:33:42
78052.0003 Feb 2018 06:55:48
65765.0031 Jan 2018 03:31:27
69834.0026 Jan 2018 21:18:04
78468.0023 Jan 2018 21:26:34
65949.0021 Jan 2018 22:34:08
78966.0017 Jan 2018 20:55:11
80835.0014 Jan 2018 06:56:02
80180.0012 Jan 2018 05:26:42
71047.0008 Jan 2018 00:29:23
69875.0004 Jan 2018 20:27:47
78139.0002 Jan 2018 07:42:11
66042.0028 Dec 2017 19:51:28
78464.0026 Dec 2017 21:14:36
66211.0022 Dec 2017 04:00:56
77558.0018 Dec 2017 22:12:55
69641.0016 Dec 2017 07:59:18
79998.0014 Dec 2017 06:56:43
80621.0009 Dec 2017 19:57:28
66337.0007 Dec 2017 19:40:10
77075.0003 Dec 2017 11:26:37
78289.0030 Nov 2017 13:28:18
 30 Nov 2017 13:28:18
78163.0026 Nov 2017 20:00:34
69641.0023 Nov 2017 21:31:01
74978.7521 Nov 2017 04:02:41
67617.0017 Nov 2017 21:28:42
67617.0014 Nov 2017 20:49:28
81756.7411 Nov 2017 05:05:10
70107.2509 Nov 2017 07:14:19
76497.0004 Nov 2017 05:02:47
70331.0031 Oct 2017 21:16:31
 31 Oct 2017 21:16:31
81568.2628 Oct 2017 12:07:23
69664.0024 Oct 2017 10:46:33
65587.0021 Oct 2017 02:31:34
80081.0018 Oct 2017 12:56:01
74307.0014 Oct 2017 14:05:52
 14 Oct 2017 14:05:52
76933.7011 Oct 2017 14:24:55
77961.5708 Oct 2017 04:19:37
74424.0005 Oct 2017 06:02:12
 05 Oct 2017 06:02:12
80421.4329 Sep 2017 23:23:44
80192.3026 Sep 2017 06:15:14
68695.0022 Sep 2017 22:06:52
76879.0020 Sep 2017 06:37:37
 20 Sep 2017 06:37:37
78899.0017 Sep 2017 03:19:34
67380.0013 Sep 2017 20:28:34
78148.0010 Sep 2017 22:06:13
72605.0008 Sep 2017 00:15:47
76981.0005 Sep 2017 23:21:27
80606.0002 Sep 2017 14:09:42
81193.0029 Aug 2017 14:22:36
73845.0026 Aug 2017 12:26:58
67380.0022 Aug 2017 20:56:55
69573.0019 Aug 2017 23:42:57
78853.0017 Aug 2017 05:30:49
77767.0013 Aug 2017 22:53:23
80143.0010 Aug 2017 03:52:20
75382.0006 Aug 2017 23:56:56
 06 Aug 2017 23:56:56
81146.0004 Aug 2017 06:21:04
66255.0031 Jul 2017 19:57:09
69951.0027 Jul 2017 22:41:25
76953.0025 Jul 2017 06:31:34
78335.0022 Jul 2017 21:45:02
78544.0017 Jul 2017 20:57:16
81397.8015 Jul 2017 04:38:31
68654.0010 Jul 2017 19:32:01
77277.0009 Jul 2017 05:41:07
77464.0006 Jul 2017 00:57:23
 06 Jul 2017 00:57:23
78309.0001 Jul 2017 21:40:42
 01 Jul 2017 21:40:42
67369.0029 Jun 2017 17:00:26
 29 Jun 2017 17:00:26
78090.2025 Jun 2017 21:45:45
81041.0023 Jun 2017 06:13:11
76037.0017 Jun 2017 22:48:21
68381.0015 Jun 2017 05:24:54
81468.3710 Jun 2017 04:33:16
78570.0008 Jun 2017 21:10:23
73638.0006 Jun 2017 06:15:42
 06 Jun 2017 06:15:42
56579.0003 Jun 2017 20:34:55
81656.6331 May 2017 06:26:23
78570.0026 May 2017 21:47:52
67191.0023 May 2017 10:56:33
72242.0020 May 2017 08:01:37
77957.0017 May 2017 04:58:21
76850.0013 May 2017 01:00:39
77662.0009 May 2017 00:28:32
65934.0004 May 2017 00:28:30
81258.0030 Apr 2017 02:07:10
70465.0027 Apr 2017 23:27:38
74813.0023 Apr 2017 18:43:41
77957.0020 Apr 2017 23:18:35
76250.0017 Apr 2017 01:15:53
66134.0012 Apr 2017 02:30:39
79503.0010 Apr 2017 23:05:44
69441.0008 Apr 2017 11:39:28
79480.0004 Apr 2017 01:22:23

 

 

 

3 ACCEPTED SOLUTIONS
Sean
Community Champion
Community Champion

And same for the MovingAverage

MovingAverage =
CALCULATE (
    SUM ( 'Shiptracking history'[Production] ),
    DATESINPERIOD (
        'Shiptracking history'[Date],
        LASTDATE ( 'Shiptracking history'[Date] ),
        -10,
        DAY
    )
)
    / 10
    + 0

Hope this helps! Smiley Happy

Works with the sample data!

View solution in original post

Sean
Community Champion
Community Champion

Okay hopefully this will solve it!

First things first go back to the Query Editor

1) Select the Date Column - Add Column tab - Time dropdown/button - select Time Only

2) with Date Column still selected - Date dropdown/button - select Date Only

3) Rename the original Date Column - Time and Date (or as you wish) and Date.1 rename just Date

4) Home tab - Close and Apply

Then

5) Create a Calendar Table - Modeling tab - click New Table

Calendar Table = CALENDAR ( MIN('Table'[Date]), MAX('Table'[Date]) )

6) Set up the Relationship between the 2 tables based on the 2 date columns

7) And this is your New Moving Average Measure

MovingAverage Measure Calendar =
CALCULATE (
    SUM ( 'Table'[Production] ),
    DATESINPERIOD (
        'Calendar Table'[Date],
        LASTDATE ( 'Calendar Table'[Date] ),
        -10,
        DAY
    )
)
    / 10
    + 0

😎 You can add a "Between" Date Slicer if you wish just make sure you use the Date from the Calendar

9) Create a Line Chart - add the Date from the Calendar to the axis and deselect the Date Hierarchy if it defaults to it

10) Add the New Moving Average to the Values

Tell me this works! Smiley Happy

View solution in original post

Sean
Community Champion
Community Champion

Wrap the calculation in CALCULATE to have Row Context

Production Measure New = 
SUMX (
    FILTER ( 'Calendar Table', 'Calendar Table'[Date] <= TODAY () ),
    CALCULATE ( SUM ( 'Table'[Production] ) + 0 )
)

View solution in original post

27 REPLIES 27
v-cherch-msft
Microsoft
Microsoft

Hi @Anonymous

 

You may try to replace the null value with "0" in query editor.

 

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

@v-cherch-msft thanks, it didn't work. I have provided more details in my post, in case that is helpful

Sean
Community Champion
Community Champion

@Anonymous

Try these 2 things:

1) Right click on the date hierarchy in you axis and select - Show Items with No Data

2) Then add zero + 0 to the Measures that calculate the daily production

Let me know of this works! Smiley Happy

Anonymous
Not applicable

@Sean thanks, it didn't work. I have provided more details in my post, in case that is helpful

Sean
Community Champion
Community Champion

This response is from my phone. So I haven’t had a chance to try the sample data.

However you need to add zero to the aggregated amounts

Production+0 = SUM ( 'Shiptracking history'[Production] )  + 0

and same with the moving average Smiley Happy

Anonymous
Not applicable

Thanks! I might be not understanding what you mean... Check out what I get if I do what I think you mean. I get a very large number, I don't know where that number comes from!

 

That sum results in a large number which I don't recogniseThat sum results in a large number which I don't recognise

 

The correct order of magnitude is ~0.7M, not 300MThe correct order of magnitude is ~0.7M, not 300M

Sean
Community Champion
Community Champion

@Anonymous

That should me a MEASURE not a COLUMN

Production Measure = SUM ( 'Table'[Production] ) + 0

Then place the Measure in the Values area of your Line Chart.

That should do it! Smiley Happy

Anonymous
Not applicable

@Sean Oh man! It works, that's it for the monthly chart, thank you so much!   🙂

Sean
Community Champion
Community Champion

And same for the MovingAverage

MovingAverage =
CALCULATE (
    SUM ( 'Shiptracking history'[Production] ),
    DATESINPERIOD (
        'Shiptracking history'[Date],
        LASTDATE ( 'Shiptracking history'[Date] ),
        -10,
        DAY
    )
)
    / 10
    + 0

Hope this helps! Smiley Happy

Works with the sample data!

Anonymous
Not applicable

@Sean Thank you. The Moving Average does not work for me... I created a measure copy-pasting your code. Power BI is still interpolating when data has gaps. In March there was no production so the 10-day moving average should be zero. Does it work for you? What am I doing wrong here?

 

There is no production in March so moving average should be zero. Power BI is still interpolatingThere is no production in March so moving average should be zero. Power BI is still interpolating

Sean
Community Champion
Community Champion

Yes works with the sample data you provided!

Show Zero Production.png

 

EDIT: I switched to Categorical Axis only for the picture above - to show March 2018 specifically! Smiley Happy

 

Anonymous
Not applicable

@Sean thanks so much for your help and patience. I am doing something wrong. Maybe the problem is with my axis. Check the picture below, it does not work for me. The title says "by Date" whereas yours says "by Year and Month". I wonder if that may be the reason why it does not work for me? It is odd that it works for you and not for me, surely I am making a mistake somewhere.

 

Categorical axis only to show you the detail in March 2018, which does not appear. I have enabled "show items with no data"Categorical axis only to show you the detail in March 2018, which does not appear. I have enabled "show items with no data"

Anonymous
Not applicable

@Sean (I am interested in plotting that moving average by day)

Sean
Community Champion
Community Champion

Do you have a Calendar Table?
Sean
Community Champion
Community Champion

Okay hopefully this will solve it!

First things first go back to the Query Editor

1) Select the Date Column - Add Column tab - Time dropdown/button - select Time Only

2) with Date Column still selected - Date dropdown/button - select Date Only

3) Rename the original Date Column - Time and Date (or as you wish) and Date.1 rename just Date

4) Home tab - Close and Apply

Then

5) Create a Calendar Table - Modeling tab - click New Table

Calendar Table = CALENDAR ( MIN('Table'[Date]), MAX('Table'[Date]) )

6) Set up the Relationship between the 2 tables based on the 2 date columns

7) And this is your New Moving Average Measure

MovingAverage Measure Calendar =
CALCULATE (
    SUM ( 'Table'[Production] ),
    DATESINPERIOD (
        'Calendar Table'[Date],
        LASTDATE ( 'Calendar Table'[Date] ),
        -10,
        DAY
    )
)
    / 10
    + 0

😎 You can add a "Between" Date Slicer if you wish just make sure you use the Date from the Calendar

9) Create a Line Chart - add the Date from the Calendar to the axis and deselect the Date Hierarchy if it defaults to it

10) Add the New Moving Average to the Values

Tell me this works! Smiley Happy

Drew248
Frequent Visitor

Hello Sean @Sean , is there a way to do this if i have my date as "2018-01" format for example. i can format it as a date but its still not working for me.

 

thank you 

 

heres a sample of the measure i created thus far

 

 

All Other Customers Qty = CALCULATE(SUM(Data[QTY]),Data[customer account]<>"WAY010414",Data[customer account]<>"WAY010090") 
Anonymous
Not applicable

This works beautifully! And I have learned a lot from this exchange. Thank you so much. Just one final question to nail this job: How can I get rid of the points that do not have data because they are in the future? Historical points without data must be shown as zero, as they are, that is great. But future points must not be shown at all. How do I tell Power BI that those are future months and that it should not plot anything from September 2018 onwards?

 

Capture10.PNG

 

Sean
Community Champion
Community Champion

Production Measure 2 =
IF (
    MAX ( 'Calendar Table'[Date] ) <= TODAY (),
    SUM ( 'Table'[Production] ) + 0
)
Anonymous
Not applicable

@Sean

Thank you very much! It does not work for me, see picture below. Does it work for you? It might be that I am not using your code properly. Screenshot is below.

 

Capture11.PNG

 

I have tried to experiment with the addition of #N/A or na() or FALSE() or "" at the end of the IF statement to try and make it work but I was unsuccesful

Production Measure 2 =
IF (
    MAX ( 'Calendar Table'[Date] ) <= TODAY (),
    SUM ( 'Table'[Production] ) + 0,
    #N/A or NA() or FALSE() or "" I have tried all of these things without success
)

 

I am already very grateful for all the help you have provided. If you solve this one too, I will be delighted.

 

Thanks a lot

Sean
Community Champion
Community Champion

@Anonymous

Sorry for the delay. Give this a try...

Production Measure New =
SUMX (
    FILTER ( 'Calendar Table', 'Calendar Table'[Date] <= TODAY () ),
    SUM ( 'Table'[Production] ) + 0
)

HTH! Smiley Happy

Helpful resources

Announcements
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

BizApps LATAM 2023

Business Application LATAM Summit 2023

Join the biggest FREE Business Applications Event in LATAM this February.

Power Platform Bootcamp

Global Power Platform Bootcamp

In this bootcamp we will deep-dive into Microsoft’s Power Platform stack with hands-on sessions and labs, delivered to you by experts and community leaders.