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
Anonymous
Not applicable

Only displaying 0 when between other Data

Goodday,

 

I have a problem and hope you guys can help. I have the following graph, where i replaced blank values with 0:

JemKoel_1-1659608835154.png

My goal is to make it like this

JemKoel_3-1659609303874.png

 

 

This Graph Follows a slicer that is on the page.

To make the graph more concise i am trying to keep the values before and after any data Blank, and between data i want it to display 0. As if this graph would start at 2021-12 and end at 2022-7, but dynamicly based on the slicer.

 

Based on the following link i made a measure to count it;

https://community.powerbi.com/t5/Desktop/Graph-Values-and-Zero-Values-Only-Within-Date-Range/m-p/576...

 

Count Lines =
VAR CountLines = COUNTA('Table'[UniqueKey])
VAR MaxDate = MAX('Table'[DateProduced])
VAR MinDate = MIN('Table'[DateProduced])
VAR ExistsLaterDate = NOT (ISEMPTY (FILTER (ALLSELECTED ('Table'), 'Table'[DateProduced]>MaxDate)))
VAR ExistsEarlierDate = NOT (ISEMPTY (FILTER (ALLSELECTED ('Table'), 'Table'[DateProduced]<MinDate)))

Return
IF (NOT (ISBLANK (CountLines)), CountLines, IF (NOT (OR (ExistsLaterDate, ExistsEarlierDate)), 0))
 
Sadly enough this only returns the rows with Data, and not anything else. 
JemKoel_2-1659609193310.png

I have been fiddeling with the NOTS, <> and all other things to get it to work, but i am just not able. Do you guys have any idea how to solve this? 

 

 

 

 

 

1 ACCEPTED SOLUTION
daXtreme
Solution Sage
Solution Sage

daXtreme_0-1659619021192.png

daXtreme_1-1659619055629.pngdaXtreme_2-1659619091277.png

daXtreme_3-1659619145387.png

Dates is a dim that stores all dates from the 2000 year.

Graph Value = 
var CurrentDate = SELECTEDVALUE( Dates[Date] )
var MinDateWithNonZeroData =
    CALCULATE(
        MINX(
            FILTER(
                Graph,
                Graph[Value] > 0
            ),
            Graph[Date]
        ),
        ALLSELECTED( Dates )
    )
var MaxDateWithNonZeroData =
    CALCULATE(
        MAXX(
            FILTER(
                Graph,
                Graph[Value] > 0
            ),
            Graph[Date]
        ),
        ALLSELECTED( Dates )
    )
var GraphValue = 
    if( MinDateWithNonZeroData <= CurrentDate 
            && CurrentDate <= MaxDateWithNonZeroData
            && not ISBLANK( MinDateWithNonZeroData ),
        CALCULATE(
            SUM( Graph[Value] ) + 0,
            TREATAS(
                { CurrentDate },
                Graph[Date]
            )
        )
    )
return
    GraphValue

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Thank you very much! It works great! I even got it working with just Year-Month Values

 

JemKoel_0-1659682672204.png

 

daXtreme
Solution Sage
Solution Sage

daXtreme_0-1659619021192.png

daXtreme_1-1659619055629.pngdaXtreme_2-1659619091277.png

daXtreme_3-1659619145387.png

Dates is a dim that stores all dates from the 2000 year.

Graph Value = 
var CurrentDate = SELECTEDVALUE( Dates[Date] )
var MinDateWithNonZeroData =
    CALCULATE(
        MINX(
            FILTER(
                Graph,
                Graph[Value] > 0
            ),
            Graph[Date]
        ),
        ALLSELECTED( Dates )
    )
var MaxDateWithNonZeroData =
    CALCULATE(
        MAXX(
            FILTER(
                Graph,
                Graph[Value] > 0
            ),
            Graph[Date]
        ),
        ALLSELECTED( Dates )
    )
var GraphValue = 
    if( MinDateWithNonZeroData <= CurrentDate 
            && CurrentDate <= MaxDateWithNonZeroData
            && not ISBLANK( MinDateWithNonZeroData ),
        CALCULATE(
            SUM( Graph[Value] ) + 0,
            TREATAS(
                { CurrentDate },
                Graph[Date]
            )
        )
    )
return
    GraphValue

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.