Forum Discussion

Pawel_J's avatar
Pawel_J
Frequent Visitor
2 years ago
Solved

Line and stacked column chart – displaying all months when using legend

 

Hello,

 

In my sample data model I have 2 tables. First table contains information about sales, the second table is a date table created using DAX. 

 

I’m currently facing an issue with my line and stacked column chart. I’m trying to display the monthly sales amount in columns and the running total in a line. For the first scenario the visual is working correctly and shows all the months of the year on the x-axis, even if there were no sales in a specific month:

The situation changes when I am adding a column legend, the months with no sales disappear:

I’m looking for a solution that allows me to include the column legend without losing the display of months with zero sales.

 

Below I am sending the sample sales table:

 

 

CompanyTransaction dateFruit nameFruits sold
A11/10/2022Banana4
A11/10/2022Apple2
A12/5/2022Apple1
A1/9/2023Apple3
B1/9/2023Banana3
A1/10/2023Banana2
A1/20/2023Apple4
B2/2/2023Apple12
A2/28/2023Apple2
B3/17/2023Banana3
B4/13/2023Apple4
A4/26/2023Apple6
A5/1/2023Apple3
A6/7/2023Apple8
A6/7/2023Apple3
A7/13/2023Apple2
B8/21/2023Apple2
A10/30/2023Apple5
A11/10/2023Banana4
A12/5/2023Apple1

 

Here is the date table created using DAX:

Date = 
VAR MinYear = YEAR ( MIN ( 'Fruits sales'[Transaction date] ) )
VAR MaxYear = YEAR ( MAX ('Fruits sales'[Transaction date] ) )
RETURN
ADDCOLUMNS (
    FILTER (
        CALENDARAUTO( ),
        AND ( YEAR ( [Date] ) >= MinYear, 
              YEAR ( [Date] ) <= MaxYear )
    ),
    "Year", YEAR ( [Date] ),
    "Month Name", FORMAT ( [Date], "mmmm" ),
    "Month Number", MONTH ( [Date] ),
    "Quarter", FORMAT( [Date], "\QQ" )
)

 

Here is the relationship:

 

Here is the running total formula:

Running Total = 
CALCULATE (
    SUM('Fruits sales'[Fruits sold]),
    DATESYTD( 'Date'[Date] )
)

 

Any help or guidance would be greatly appreciated.  

  • Anonymous's avatar
    Anonymous
    2 years ago

    Thanks for the reply from Ritaf1983 , please allow me to provide another insight: 
    Hi  Pawel_J ,

     

    You can click X-axis - [Month Name] - Show items with no data.

     

    Best Regards,

    Liu Yang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

3 Replies

  • Hi Pawel_J 
    You can add 0 to the measure of bars.
    For example (from my sample file) :

    Total sales (K/$) = SUMX('orders',('orders'[Unit price]- [Discount])*'orders'[Quantity])+0

    The pbix is attached

    If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thanks for the reply from Ritaf1983 , please allow me to provide another insight: 
    Hi  Pawel_J ,

     

    You can click X-axis - [Month Name] - Show items with no data.

     

    Best Regards,

    Liu Yang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • Pawel_J's avatar
    Pawel_J
    Frequent Visitor

    Thank you very much for your responses. In my case I was using a measure only to calculate the running total and "Show items with no data" worked.