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
huguestremblay
Helper II
Helper II

Dynamic date axis on chart showing dates with no data

I have researhed and found similar posts but could still not figure out how to get this to work...

 

I have a bar chart that shows a distinct count of ID by month.  I want the users to be able to select a date range with a slicer and have the chart automatically update to show the data in the selected date range.  I also want the months that do not have any records to show on the axis, without a bar, but only those months that are within the selected date range.

 

This is all of my data:

huguestremblay_0-1642779329621.png

If I select 2021 in a slicer, I either get this if "show items with no data" is checked - all of the months outside of 2021 are showing on the chart with no bar, I do not want to see those months

huguestremblay_1-1642779451848.png

Or this if I uncheck "show items with no data" - the months that have no records but are withing the selected date range are not showing (i.e. May, June, November and December).

huguestremblay_3-1642779561509.png

How can I get all of the 2021 months to show, including May, June, November and December?

 

My pbix file is available here.

 

Thanks!

1 ACCEPTED SOLUTION
v-chenwuz-msft
Community Support
Community Support

Hi @huguestremblay ,

 

I do not see the bar chart as your screenshot in your pbix file, please check it.

 

I have a method you can try.
1 Create a date table for the slicer.

Date for slicer = VALUES('Table'[Date])


2 Create a measure as follows:

Measure =
VAR _count =
    IF( ISBLANK( SUM( 'Table'[Values] ) ), 0, SUM( 'Table'[Values] ) )
VAR _mindate =
    MIN( 'Date for slicer'[Date] )
VAR _maxdate =
    MAX( 'Date for slicer'[Date] )
RETURN
    IF(
        AND(
            DATE( SELECTEDVALUE( 'Table'[Date].[Year] ), SELECTEDVALUE( 'Table'[Date].[MonthNo] ), 1 ) >= _mindate,
            DATE( SELECTEDVALUE( 'Table'[Date].[Year] ), SELECTEDVALUE( 'Table'[Date].[MonthNo] ) + 1, 1 ) - 1 <= _maxdate
        ),
        _count,
        BLANK()
    )

3 Uncheck "show items with no data"

Result:

vchenwuzmsft_0-1643104821992.png

 

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

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

 

View solution in original post

3 REPLIES 3
v-chenwuz-msft
Community Support
Community Support

Hi @huguestremblay ,

 

I do not see the bar chart as your screenshot in your pbix file, please check it.

 

I have a method you can try.
1 Create a date table for the slicer.

Date for slicer = VALUES('Table'[Date])


2 Create a measure as follows:

Measure =
VAR _count =
    IF( ISBLANK( SUM( 'Table'[Values] ) ), 0, SUM( 'Table'[Values] ) )
VAR _mindate =
    MIN( 'Date for slicer'[Date] )
VAR _maxdate =
    MAX( 'Date for slicer'[Date] )
RETURN
    IF(
        AND(
            DATE( SELECTEDVALUE( 'Table'[Date].[Year] ), SELECTEDVALUE( 'Table'[Date].[MonthNo] ), 1 ) >= _mindate,
            DATE( SELECTEDVALUE( 'Table'[Date].[Year] ), SELECTEDVALUE( 'Table'[Date].[MonthNo] ) + 1, 1 ) - 1 <= _maxdate
        ),
        _count,
        BLANK()
    )

3 Uncheck "show items with no data"

Result:

vchenwuzmsft_0-1643104821992.png

 

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

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

 

Hello,  

What I need is a DISTINCTCOUNT (not a SUM) so I have udpated your measure accordingly and it appears to work in my test report.  I will transfer to my full report now.

Thank you!

parry2k
Super User
Super User

@huguestremblay there is a great video on this How to return 0 instead of BLANK in DAX - SQLBI

 

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.