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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
zhona9
Resolver I
Resolver I

Line in Line and Stacked Chart not filtering by date

I have a line and stacked chart which used to just show the markers (round dots). I wanted to connect them with a line. I googled past solutions and added "+0" to my measure to make the markers connected by lines. However once I did this, the chart is no longer filtering by the reported date in my slicer.

 

The measure in my line and stacked chart is as follows:

InvestigationRequired = CALCULATE(COUNT(g360_Incidents[incident_number]), KEEPFILTERS(g360_Incidents[is_an_investigation_required]="Yes")) + 0

 

See the chart now:

zhona9_0-1683770136450.png

How can I fix this? 

 

Thank you.

1 ACCEPTED SOLUTION
zhona9
Resolver I
Resolver I

Thanks for helping. In the end this dashboard was too complex to build with the existing datasource. I had to create an intermediate datasource using SQL and excel macro to reflect the data. Somehow when I did that, the visual showed correctly without having to use measures. It is probably to do with the fact that the new table I generate shows a "0" when the value is 0. So on hindsight for others, a new column to convert blank values to 0 would have worked too.

View solution in original post

6 REPLIES 6
zhona9
Resolver I
Resolver I

Thanks for helping. In the end this dashboard was too complex to build with the existing datasource. I had to create an intermediate datasource using SQL and excel macro to reflect the data. Somehow when I did that, the visual showed correctly without having to use measures. It is probably to do with the fact that the new table I generate shows a "0" when the value is 0. So on hindsight for others, a new column to convert blank values to 0 would have worked too.

danextian
Super User
Super User

Hi @zhona9 ,

 

Adding 0 after a measue  returns 0 even if a date has no actual value when using a separate dates table. Try using a condition so the measure doesn't return 0 when there's no actual value or when the dates are not within min and max of dates with values.  See which one below works for you.

=
IF ( [measure] <> BLANK (), [measure] + 0 )
=
VAR MinDateWithValue =
    //min date in the current filter context
    CALCULATE (
        MIN ( Dates[Date] ),
        FILTER ( ALLSELECTED ( Dates ), SUM ( Fact[Value] ) <> BLANK () )
    )
VAR MaxDateWithValue =
    //max date in the current filter context
    CALCULATE (
        MAX ( Dates[Date] ),
        FILTER ( ALLSELECTED ( Dates ), SUM ( Fact[Value] ) <> BLANK () )
    )
RETURN
    CALCULATE (
        [measure] + 0,
        FILTER (
            dates,
            dates[Date] >= MinDateWithValue
                && dates[Date] <= MaxDateWithValue
        )
    )
=
VAR MinDateWithValue =
    CALCULATE (
        MIN ( Dates[Date] ),
        FILTER ( ALLSELECTED ( Dates ), SUM ( Fact[Value] ) <> BLANK () )
    )
VAR MaxDateWithValue =
    CALCULATE (
        MAX ( Dates[Date] ),
        FILTER ( ALLSELECTED ( Dates ), SUM ( Fact[Value] ) <> BLANK () )
    )
RETURN
    IF (
        SELECTEDVALUE ( DAtes[Date] ) >= MinDateWithValue
            && SELECTEDVALUE ( DAtes[Date] ) <= MaxDateWithValue,
        [measure] + 0
    )

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi,

 

Thanks for the fast reply.

 

I tried this:

InvestigationRequired = 
var countinvestigation = 
CALCULATE(COUNT(g360_Incidents[incident_number]), KEEPFILTERS(g360_Incidents[is_an_investigation_required]="Yes")) 
return 
If (countinvestigation <> blank(), countinvestigation + 0)

 

However it brings me back to square one, I still don't see a continuous line:

zhona9_0-1683771936961.png

 

Ideally I want to see something like this (from an excel chart):

zhona9_1-1683771982835.png

I do want to see the line go down to zero, but I only want it displayed within the filtered reported dates.

Have you tried the other measures? I don't have sample data model to test the  measures.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

For using the min/max date, is there anyway to reference the min/max date selected using the slicer?

Hi @zhona9 ,

 

You need to be able to tell the measure what are the min and max dates that have values based on the current filter context so even if your dates table has dates from before and after  the dates in your fact  table with values, the filter will be restricted to those.  That's the expected behaviour of my second solution. However  after several tests, adding 0 even within the measure still returns zero even when the date is not within the range set. The workaround is to create a helper (calculated) column in your dates table that contains 0. Sum of Values2  in the screenshot below is the result of using the second formula.

danextian_0-1683781894808.png

New formula would be something like:

Sum of Values3 =
VAR MinDateWithValue =
    CALCULATE (
        MIN ( Dates2[Date] ),
        FILTER ( ALLSELECTED ( Dates2 ), [Sum of Values] <> BLANK () )
    )
VAR MaxDateWithValue =
    CALCULATE (
        MAX ( Dates2[Date] ),
        FILTER ( ALLSELECTED ( Dates2 ), [Sum of Values] <> BLANK () )
    )
RETURN
    CALCULATE (
        SUM ( 'DataTable'[Values] ) + SUM ( Dates[0] ),
        FILTER (
            Dates2,
            Dates2[Date] >= MinDateWithValue
                && Dates2[Date] <= MaxDateWithValue
        )
    )

 

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.