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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Bilal_Anwar
New Member

Show null values as "0" in line chart for last 4 weeks data

Hi,

 

I need help in fixing the line chart. i want to indicate the values in last 4 weeks including if the value is zero as well.

 

here is the issue brief.

 

i have 3 tables.

1- FACT Table - tb_data 

2- DATES Table - Tb_dimdate

3- Dummy Date Table - dummydates (which is copy of tb_date and is being used to get x-axis range for last 2 weeks based on Max(Tb_date)

FACT Table and DATES Table are linked.

 

i have created measure to calculate the data in last 4 weeks. here is the DAX expression.

Last 4 weeks Data =
VAR _maxdate = MAX(tb_DimDate[Date])
VAR _lastinperiod =
DATESINPERIOD(DummyDates[Date],_maxdate,-28,day)
RETURN

CALCULATE(
SUM(Tb_Data[Value]),
REMOVEFILTERS(tb_DimDate[Date]),
KEEPFILTERS(_lastinperiod),
USERELATIONSHIP(tb_DimDate[Date],DummyDates[Date])
)

Tables have following relationship

 

Bilal_Anwar_0-1700686717946.png

 

the line chart and matrix visual show only dates which have values > 0. i want to include even "0" values.

Bilal_Anwar_1-1700687210228.png

i have tried both alternate solutions.

1- show items with no data (x-axis)

2- calculate( if(ISBLANK(sum() , 0 , sum() )

and both are not working.

 

 

In both cases the x-axis range changes to complete dates table.

Bilal_Anwar_0-1700687184460.png

 

Requirement: i need data for 4 weeks including 0 values in line chart.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Bilal_Anwar ,

You can follow the steps below to get it:

1. Please delete the relationship between Tb_Data table and DummyDates table

vyiruanmsft_0-1700792317225.png

2. Update the formula of measure [Last 4 weeks Data] as below if you applied the date field of DummyDates table on X axis field of line chart

Last 4 weeks Data =
VAR _maxdate =
    MAX ( tb_DimDate[Date] )
VAR _seldate =
    SELECTEDVALUE ( DummyDates[Date] )
VAR _lastinperiod =
    DATESINPERIOD ( DummyDates[Date], _maxdate, -28, DAY )
RETURN
    IF (
        _seldate IN _lastinperiod,
        CALCULATE (
            SUM ( Tb_Data[Value] ),
            REMOVEFILTERS ( tb_DimDate[Date] ),
            KEEPFILTERS ( _lastinperiod ),
            FILTER ( tb_DimDate, tb_DimDate[Date] = _seldate )
        ) + 0,
        BLANK ()
    )

If the above one can't help you get the expected result, please provide some raw data in your table 'Tb_Data' (exclude sensitive data) with Text format and your visual settings. It would be helpful to find out the solution. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Bilal_Anwar ,

You can follow the steps below to get it:

1. Please delete the relationship between Tb_Data table and DummyDates table

vyiruanmsft_0-1700792317225.png

2. Update the formula of measure [Last 4 weeks Data] as below if you applied the date field of DummyDates table on X axis field of line chart

Last 4 weeks Data =
VAR _maxdate =
    MAX ( tb_DimDate[Date] )
VAR _seldate =
    SELECTEDVALUE ( DummyDates[Date] )
VAR _lastinperiod =
    DATESINPERIOD ( DummyDates[Date], _maxdate, -28, DAY )
RETURN
    IF (
        _seldate IN _lastinperiod,
        CALCULATE (
            SUM ( Tb_Data[Value] ),
            REMOVEFILTERS ( tb_DimDate[Date] ),
            KEEPFILTERS ( _lastinperiod ),
            FILTER ( tb_DimDate, tb_DimDate[Date] = _seldate )
        ) + 0,
        BLANK ()
    )

If the above one can't help you get the expected result, please provide some raw data in your table 'Tb_Data' (exclude sensitive data) with Text format and your visual settings. It would be helpful to find out the solution. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

 

Thank you @Anonymous for detailed reponse. i get what you have recommended and definitely it will work as well. 

i looked at my data tables and found out that during unpivoting the data column i was replacing the "null" values with "0" and later after unpivoting i was replacing it back to null values. which was resulting in null values and ultimately wasnt working with my formula for dates in period. now i have got it sorted. i will use your method and test it. DAX looks ok to me, should work.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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